[pygtk] Looking for help with comboboxes
Gerald Britton
gerald.britton at gmail.com
Tue Apr 14 22:39:23 WST 2009
Hi -- I'm trying to learn how to use comboboxes. I worked up a little
program to try to test it out (below, with imbedded glade). I tried
two methods to get stuff to show in the box, but to no avail. In the
first method I used the append_text method on the combobox. In the
second method I used the append method on the liststore. Obviously
I'm missing something but this newbie can't see what. I tried both
methods separately and together with the same (bad) result.
Would someone be able to point out what I am missing?
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>
</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) # 1. try to append the text to the combobox
l.append(["line %d" % i]) # 2. try to add the text to the
liststore in the combobox.
w.show()
gtk.main()
--
Gerald Britton
More information about the pygtk
mailing list