Python Gtk Adding Signal To A Combo Box
I create a combo box using PyGTK: fileAttrCombo = gtk.ComboBox(); I want to attach a signal handler for this combo box. This signal handler handles when user change selection in
Solution 1:
The combobox has a "changed" signal.
This is a nice minimal example of using it.
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
classComboBoxExample:def__init__(self):
window = gtk.Window()
window.connect('destroy', lambdaw: gtk.main_quit())
combobox = gtk.combo_box_new_text()
window.add(combobox)
combobox.append_text('Select a pie:')
combobox.append_text('Apple')
combobox.append_text('Cherry')
combobox.append_text('Blueberry')
combobox.append_text('Grape')
combobox.append_text('Peach')
combobox.append_text('Raisin')
combobox.connect('changed', self.changed_cb)
combobox.set_active(0)
window.show_all()
returndefchanged_cb(self, combobox):
model = combobox.get_model()
index = combobox.get_active()
ifindex:
print 'I like', model[index][0], 'pie'returndefmain():
gtk.main()
returnif __name__ == "__main__":
bcb = ComboBoxExample()
main()
Post a Comment for "Python Gtk Adding Signal To A Combo Box"