How to reuse widget tree from glade file using GtkBuilder?

I want to complete gtk.notebook on the fly. Each time the user opens the file, a new tab for the laptop is created. pretty straight forward. my problem is that I use a clearing to create ui, and the notebook tab should have a child widget tree (scrolledwindow-> viewport-> alignment-> frame). in my glade file, I have a notepad tab for the template that I want to use several times, so I donโ€™t need to encode the whole tree in regular gtk. with libglade, you can reuse the widget tree as described here in pygtk faq: http://faq.pygtk.org/index.py?file=faq22.011.htp&req=show . How to do it with GtkBuilder?

thanks in advance,

Arthur

+4
source share
1 answer

Do it with GtkBuilder:

builder = gtk.Builder() builder.add_from_file("GUI.xml") builder.connect_signals(self) self.window1 = builder.get_object("window1") self.window1.show() 

change

I was initially mistaken, it seems that gtkbuilder makes an instance of objects when it adds. Thus, the ideal way to do this would be to add the widget manually using the line

 builder.add_from_string(""" <interface> <object class="GtkWindow" id="window1"> <child> <object class="GtkComboBox" id="combobox1"> <property name="model">liststore1</property> </object> </child> </object> </interface>""") self.window1 = builder.get_object("window1") 

Hope it works!

+1
source

All Articles