如何在GTK.Stack中获取可见子项的索引

时间:2016-10-28 14:19:07

标签: python gtk pygobject

可以在Gtk.Stack中获取可见的索引吗?

示例:

>>> stack = Gtk.Stack()
>>> stack.add_named(any_widget1, 'any_widget1') # Index 0
>>> stack.add_named(any_widget2, 'any_widget2') # Index 1
>>> stack.add_named(any_widget3, 'any_widget3') # Index 2
>>>
>>> stack.get_visible_child_index()
0

这可能吗?

1 个答案:

答案 0 :(得分:3)

Stack文档包含position子属性:

child = stack.get_visible_child()
if child is not None:
    position = stack.child_get_property(child, "position")