PyGobject(四十二)布局容器之ButtonBox
2016-07-30 10:49
387 查看
Gtk.ButtonBox
Gtk.ButtonBox能够控制子部件的排列方式,如居中,靠左,靠右等。还能够控制子部件的主次关系,见例子。继承关系
Gtk.ButtonBox是Gtk.Box的直接子类Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (orientation) |
get_child_non_homogeneous (child) | |
get_child_secondary (child) | |
get_layout () | |
set_child_non_homogeneous (child, non_homogeneous) | |
set_child_secondary (child, is_secondary) | |
set_layout (layout_style) |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
layout-style | Gtk.ButtonBoxStyle | r/w/en | How to lay out the buttons in the box. Possible values are: spread, edge, start and end |
Signals
Name | Short Description |
---|
例子
代码:
#!/usr/bin/env python3 # Created by xiaosanyu at 16/6/28 # section 059 TITLE = "ButtonBox" DESCRIPTION = "" import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk class ButtonBoxWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="ButtonBox Demo") self.set_border_width(10) main_vbox = Gtk.VBox() self.add(main_vbox) box = Gtk.ButtonBox(layout_style=Gtk.ButtonBoxStyle.EDGE) main_vbox.pack_start(box, False, False, 10) child1 = Gtk.Button(label="button1") child1.set_size_request(150, 30) child2 = Gtk.Button(label="button2") child3 = Gtk.Button(label="button3") box.add(child1) box.add(child2) box.add(child3) # set_child_non_homogeneous 设置False,其它孩子大小跟它同等,设置True,其他孩子尺寸跟它不一样 box.set_child_non_homogeneous(child1, True) # set_child_secondary 设置孩子显示在次要位置.如果ButtonBox从左到右方向.则孩子显示在最右边. box.set_child_secondary(child2, True) frame_horz = Gtk.Frame.new("Horizontal Button Boxes") main_vbox.pack_start(frame_horz, True, True, 10) vbox = Gtk.VBox() vbox.set_border_width(10) frame_horz.add(vbox) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "Spread", 40, Gtk.ButtonBoxStyle.SPREAD), True, True, 0) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "Edge", 40, Gtk.ButtonBoxStyle.EDGE), True, True, 5) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "Start", 40, Gtk.ButtonBoxStyle.START), True, True, 5) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "End", 40, Gtk.ButtonBoxStyle.END), True, True, 5) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "Center", 40, Gtk.ButtonBoxStyle.CENTER), True, True, 5) vbox.pack_start(self.create_bbox(Gtk.Orientation.HORIZONTAL, "Expand", 0, Gtk.ButtonBoxStyle.EXPAND), True, True, 5) frame_vert = Gtk.Frame.new("Vertical Button Boxes") main_vbox.pack_start(frame_vert, True, True, 10) hbox = Gtk.HBox() hbox.set_border_width(10) frame_vert.add(hbox) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "Spread", 10, Gtk.ButtonBoxStyle.SPREAD), True, True, 0) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "Edge", 10, Gtk.ButtonBoxStyle.EDGE), True, True, 5) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "Start", 10, Gtk.ButtonBoxStyle.START), True, True, 5) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "End", 10, Gtk.ButtonBoxStyle.END), True, True, 5) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "Center", 10, Gtk.ButtonBoxStyle.CENTER), True, True, 5) hbox.pack_start(self.create_bbox(Gtk.Orientation.VERTICAL, "Expand", 0, Gtk.ButtonBoxStyle.EXPAND), True, True, 5) @staticmethod def create_bbox(horizontal, title, spacing, layout): frame = Gtk.Frame.new(title) bbox = Gtk.ButtonBox.new(orientation=horizontal) bbox.set_border_width(5) frame.add(bbox) bbox.set_layout(layout) bbox.set_spacing(spacing) button = Gtk.Button.new_with_label("OK") bbox.add(button) button = Gtk.Button.new_with_label("Cancel") bbox.add(button) button = Gtk.Button.new_with_label("Help") bbox.add(button) return frame def main(): win = ButtonBoxWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() if __name__ == "__main__": main()
代码解析
child1 = Gtk.Button(label="button1") child1.set_size_request(150, 30) child2 = Gtk.Button(label="button2") child3 = Gtk.Button(label="button3") box.add(child1) box.add(child2) box.add(child3)
第一组的三个按钮组要讲解set_child_non_homogeneous方法和set_child_secondary
# set_child_non_homogeneous 设置False(默认值),其它孩子大小跟它同等,设置True,其他孩子尺寸跟它不一样 box.set_child_non_homogeneous(child1, True) # set_child_secondary 设置孩子显示在次要位置.如果ButtonBox从左到右方向.则孩子显示在最右边. box.set_child_secondary(child2, True)
接下来主要介绍 Gtk.ButtonBoxStyle的使用,代码结合示例图看,比较清楚明了,不啰嗦了~
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法