views:

28

answers:

1

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?

+2  A: 

Try using a gtk.ComboBox instead of gtk.Combo, since the latter is deprecated in favor of the former. To initialise, you can you code like:

liststore = gtk.ListStore(gobject.TYPE_STRING)
for key in self.keys:
    liststore.append((key,))
combobox = gtk.ComboBox(liststore)
cell = gtk.CellRendererText()
combobox.pack_start(cell, True)
combobox.add_attribute(cell, 'text', 0)

Now you connect to the changed signal of the combobox and use its get_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.

Sven Marnach