If I have a combo box in pyGTK and would like to set a list of strings and then on clicking on one activate a command how would I do it?
At the moment I have:
self.combo_key = gtk.Combo()
self.combo_key.set_popdown_strings(self.keys)
self.combo_key.entry.set_text(db.keys()[0])
self.combo_key.entry.connect("activate", self.key_sel)
But "activate" only calls after selection, and then by pressing enter. I’m also getting a deprecation warning for gtk.Combo() but cannot find any help on using gtk.ComboBoxEntry()
Any help guys?
Try using a
gtk.ComboBoxinstead ofgtk.Combo, since the latter is deprecated in favor of the former. To initialise, you can you code like:Now you connect to the
changedsignal of thecomboboxand use itsget_active()method to ask for the item that was selected.As you might guess from this explanation, the ComboBox isn’t exactly made for this purpose. You probably want to use
gtk.Menu.