Reputation: 351
I am using a Gtk.Stack widget in PyGobject, and as i could not find any "tutorial" on how to use them, i supposed that each element of the Gtk.Stack has a name/tag.
And so i made a few elements and connected to the stack with:
add_named(element_to_add_to_stack, "Element_tag")
The fist of them was connected and successfully appeared, but whenever i set another as visible with:
set_visible_child_name("Element_tag")
Nothing happens, and after a retrieval of which elements are part of the stack:
stack.get_visible_child()
It simply returns
None
What is wrong? Is that way to use Gtk.Stack wrong?
Edit:
def main_content(self):
right_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.stack = Gtk.Stack()
self.stack.get_style_context().add_class("main-container")
self.stack.props.margin = 20
self.stack.add_named(self.gen_page1(), "page1")
self.stack.add_named(self.gen_page2(), "page2")
self.stack.add_named(self.gen_page3(), "page3")
#self.stack.set_visible_child_name("page2")
#self.stack.set_visible_child_full("page2", 1)
print((self.stack.get_visible_child()))
right_box.pack_start(self.stack, True, True, 0)
return right_box
Upvotes: 0
Views: 819
Reputation: 14587
The child widget needs to be visible (as in Widget.get_visible()
) before it can be a 'visible child'. This is not the case at this point of your code (although it would just work when the window is actually shown), but if you just do my_child_widget.set_visible (True)
before adding the child widgets to the stack, get_visible_child()
should start working.
Not the greatest design really as the set_visible_child*
functions fail totally silently...
Upvotes: 3