Search code examples
pythongtkpygobject

How to get the index of visible child in GTK.Stack


Is possible get the index of visible in Gtk.Stack?

Example:

>>> 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

This is possible?


Solution

  • The Stack documentation includes position child property:

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