i want to populate a gtk.notebo开发者_如何转开发ok on-the-fly. everytime a user opens a file, a new notebook-tab is generated. pretty straight forward. my problem is, that i use glade to build the ui and the notebook-tab should have a child widget tree (scrolledwindow->viewport-> alignment->frame). in my glade-file, i have a template notebook-tab, which i want to use multiple times, so that i dont have to code the whole tree in plain gtk. with libglade, you could reuse a widget tree as explained in the pygtk faq here: http://faq.pygtk.org/index.py?file=faq22.011.htp&req=show . How do i do this with GtkBuilder?
thanks in advance,
Arthur
Do it this way with GtkBuilder:
builder = gtk.Builder()
builder.add_from_file("GUI.xml")
builder.connect_signals(self)
self.window1 = builder.get_object("window1")
self.window1.show()
edit:
I was initially wrong, it seems that gtkbuilder does instantiate objects when it adds. So the ideal way to do this would be to add the widget in manually via a string
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")
Hopefully this works!
精彩评论