PyGobject(四)布局容器概述

Gtk+排列小部件是通过容器的。它们对终端用户是不可见的。这里有两种风格的容器:单孩子的容器,是Gtk.Bin的后代。多孩子的容器,是Gtk.Container的后代。

最常用的是垂直或水平框(Gtk.Box)和网格(Gtk.Grid)。

Gtk.Window 是单孩子容器,只能添加一个直接子部件,如果直接在其中添加多个子部件,只会显示一个,并且会提示

Attempting to add a widget with type GtkButton to a main+MyWindow, but as a GtkBin subclass a main+MyWindow can only contain one widget at a time; it already contains a widget of type GtkButton

Gtk.Window要包含多个子部件的话,需要先在其中添加一个多孩子容器,然后在容器中再添加子部件

Gtk.Container

继承关系

Gtk.Container继承关系

Methods

方法修饰词方法名及参数
add (widget)
check_resize ()
child_get (child, *prop_names)
child_get_property (child, property_name, value=None)
child_notify (child, child_property)
child_notify_by_pspec (child, pspec)
child_set (child, **kwargs)
child_set_property (child, property_name, value)
child_type ()
forall (callback, *callback_data)
foreach (callback, *callback_data)
get_border_width ()
get_children ()
get_focus_chain ()
get_focus_child ()
get_focus_hadjustment ()
get_focus_vadjustment ()
get_path_for_child (child)
get_resize_mode ()
propagate_draw (child, cr)
remove (widget)
resize_children ()
set_border_width (border_width)
set_focus_chain (focusable_widgets)
set_focus_child (child)
set_focus_hadjustment (adjustment)
set_focus_vadjustment (adjustment)
set_reallocate_redraws (needs_redraws)
set_resize_mode (resize_mode)
unset_focus_chain ()

add (widget)

添加部件到容器中

check_resize ()


child_get (child, *prop_names)

获取给定列表中所有属性的值,prop_names为list

child_get_property (child, property_name, value=None)

获取某一个属性的属性值

child_notify (child, child_property)

发送Gtk.Widget ::child-notify信号在child部件上

child_notify_by_pspec (child, pspec)


child_set (child, **kwargs)

设置child部件的属性,kwargs为字典键值对

child_set_property (child, property_name, value)

设置child部件的某一个属性的值

child_type ()

    Return type: GObject.GType

返回容器可以添加的孩子部件的类型
注意:有可能返回GObject.TYPE_NONE,表示容器已经不可以在添加孩子了。例如Gtk.Paned已经有两个孩子了,这时候child_type()就返回GObject.TYPE_NONE

forall (callback, *callback_data)

对容器的每一个直接孩子调用callback方法最好用Gtk.Container.foreach(),方法

foreach (callback, *callback_data)

Gtk.Container.forall(),

get_border_width ()

获取内边距宽度

get_children ()

    Return type: [Gtk.Widget]
返回容器的非 “internal ”孩子列表

get_focus_chain ()


get_focus_child ()

    Return type: Gtk.Widget
返回容器当前将要获得焦点的孩子,如果这个容器获得焦点,那么这个孩子就获得焦点

get_focus_hadjustment ()

    Return type: Gtk.Adjustment or None
获取焦点的水平范围(容器在哪个范围内才可以获取到焦点)
Gtk.Container.set_focus_hadjustment ()

get_focus_vadjustment ()

    Return type: Gtk.Adjustment or None
获取焦点的垂直范围(容器在哪个范围内才可以获取到焦点)

get_path_for_child (child)

    Return type: Gtk.WidgetPath
返回部件的深度

get_resize_mode ()

    Return type: Gtk.ResizeMode
获取容器调整大小模式

propagate_draw (child, cr)

绘制孩子

remove (widget)

移除某个部件

resize_children ()

Deprecated.

set_border_width (border_width)

设置容器内边距宽度

set_focus_chain (focusable_widgets)


set_focus_child (child)

设置获得焦点的孩子

set_focus_hadjustment (adjustment)

    Parameters: adjustment (Gtk.Adjustment)
设置焦点的水平范围

set_focus_vadjustment (adjustment)

    Parameters: adjustment (Gtk.Adjustment)
设置焦点的垂直范围

set_reallocate_redraws (needs_redraws)

当孩子大小变化时,容器是否自动重绘。

Deprecated.改用在调整大小事件处理方法中调用Gtk.Widget.queue_draw() 方法

set_resize_mode (resize_mode)

设置调整大小模式
Deprecated.

unset_focus_chain ()

移除焦点链

Virtual Methods

do_add (widget)
do_check_resize ()
do_child_type ()
do_composite_name (child)
do_forall (include_internals, callback, callback_data)
do_get_child_property (child, property_id, value, pspec)
do_get_path_for_child (child)
do_remove (widget)
do_set_child_property (child, property_id, value, pspec)
do_set_focus_child (child)

Properties

NameTypeFlagsShort Description
border-widthintr/w/en孩子到容器边框的距离
childGtk.Widgetw孩子,可用用来添加一个新的孩子到容器中
resize-modeGtk.ResizeModed/r/w/en调整大小的方式 deprecated

Signals

NameShort Description
add添加孩子
check-resize
remove移除孩子
set-focus-child

Gtk.Bin

继承关系

Gtk.Bin继承关系

Methods

方法修饰词方法名及参数
get_child ()

get_child

获取孩子部件

附录

Gtk.ResizeMode

class Gtk.ResizeMode
Bases: GObject.GEnum

PARENT = 0

将resize 事件传递给父容器

QUEUE = 1

将resize事件压入widget的请求队列中

IMMEDIATE = 2

立即resize. Deprecated.


再接下来的文章中将逐一介绍这些布局容器~





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值