[pygtk] Looking for help with comboboxes
Gerald Britton
gerald.britton at gmail.com
Wed Apr 15 00:25:00 WST 2009
Thanks Neil,
So, with your suggestion in place, I have the program below. I still
must be missing something though, since my combobox is still empty.
I'm wondering about your comment about linking the model to the
renderer. I tried coping the property line from the combobox, but the
builder didn't like that. What is the correct way?
glade = """
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkListStore" id="liststore">
<columns>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">Sample window with combo
box</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<signal name="destroy" handler="on_window_destroy"/>
<child>
<object class="GtkComboBox" id="combobox">
<property name="visible">True</property>
<property name="model">liststore</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1" />
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</interface>
"""
import gtk
g = gtk.Builder()
g.add_from_string(glade)
g.connect_signals({ "on_window_destroy" : gtk.main_quit })
w = g.get_object('window')
c = g.get_object('combobox')
l = g.get_object('liststore')
for i in range(10):
# c.append_text("line %d" % i)
l.append(["line %d" % i])
w.show()
gtk.main()
More information about the pygtk
mailing list