您的位置:首页 > 移动开发 > Objective-C

PyGobject(四十五)布局容器之Grid

2016-07-30 12:15 344 查看
GtkGrid
继承关系

Methods

attachchild left top width height

attach_next_to child sibling side width height

Virtual Methods

Properties

Signals

例子

附录
GtkPositionType

Gtk.Grid

网格布局容器

继承关系

Gtk.Grid是Gtk.Container的直接子类



Methods

方法修饰词方法名及参数
staticnew ()
attach (child, left, top, width, height)
attach_next_to (child, sibling, side, width, height)
get_baseline_row ()
get_child_at (left, top)
get_column_homogeneous ()
get_column_spacing ()
get_row_baseline_position (row)
get_row_homogeneous ()
get_row_spacing ()
insert_column (position)
insert_next_to (sibling, side)
insert_row (position)
remove_column (position)
remove_row (position)
set_baseline_row (row)
set_column_homogeneous (homogeneous)
set_column_spacing (spacing)
set_row_baseline_position (row, pos)
set_row_homogeneous (homogeneous)
set_row_spacing (spacing)
attach(child, left, top, width, height)

Parameters:

child (Gtk.Widget) –要添加的子部件

left (int) – 子部件左侧部件的个数,left=0表示当前部件位于第一列,以此类推

top (int) – 子部件上方的行数,top=0表示当前部件位于第一行,以此类推

width (int) – 子部件横跨的列数

height (int) – 子部件横跨的行数

attach_next_to (child, sibling, side, width, height)

Parameters:

child (Gtk.Widget) –要添加的子部件

sibling (Gtk.Widget) – 子部件要相邻的部件,如果为None,子部件要位于行开始或者结束的位置

side (Gtk.PositionType) – 子部件与sibling部件的位置关系

width (int) – 子部件横跨的列数

height (int) – 子部件横跨的行数

Virtual Methods

Properties

NameTypeFlagsShort Description
baseline-rowintr/w/enThe row to align the to the baseline when valign is Gtk.Align.BASELINE
column-homogeneousboolr/w/en列宽是否相同
column-spacingintr/w/en列间距
row-homogeneousboolr/w/en行高是否相同
row-spacingintr/w/en行间距

Signals

NameShort Description

例子



代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/13
# section 062
TITLE = "Grid"
DESCRIPTION = """
Gtk.Grid is a container which arranges its child widgets in rows and columns.
"""
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class GridWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Grid Example")
grid = Gtk.Grid()
self.add(grid)

button1 = Gtk.Button(label="Button 1")
button2 = Gtk.Button(label="Button 2")
button3 = Gtk.Button(label="Button 3")
button4 = Gtk.Button(label="Button 4")
button5 = Gtk.Button(label="Button 5")
button6 = Gtk.Button(label="Button 6")
grid.add(button1)
grid.attach(button2, 1, 0, 2, 1)
grid.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2)
grid.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1)
grid.attach(button5, 1, 2, 1, 1)
grid.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1)

def main():
win = GridWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

if __name__ == "__main__":
main()


代码解析:

grid = Gtk.Grid()
self.add(grid)


创建一个Gtk.Grid,添加到当前窗口中

接着创建6个Gtk.Button

grid.add(button1)


使用Gtk.Container.add()方法添加button1到grid中

grid.attach(button2, 1, 0, 2, 1)


使用attach方法添加button2,位于第二列第一行,横跨两列一行

grid.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2)


使用attach_next_to方法添加button3,位于button1的下方,横跨一列两行

grid.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1)


使用attach_next_to方法添加button4,位于button3的右方,横跨两列一行

grid.attach(button5, 1, 2, 1, 1)


使用attach方法添加button5,位于第二列第三行,占一列一行

grid.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1)


使用attach_next_to方法添加button6,位于button5的右方,占一列一行

附录

Gtk.PositionType

class Gtk.PositionType

Bases: GObject.GEnum

LEFT = 0

The feature is at the left edge.

RIGHT = 1

The feature is at the right edge.

TOP = 2

The feature is at the top edge.

BOTTOM = 3

The feature is at the bottom edge.

代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息