Part 7b
User Data
The Python Side
glade7.py
#!/usr/bin/env python
try:
import pygtk
pygtk.require('2.0')
except:
pass
try:
import gtk
import gtk.glade
except:
print('GTK not available')
sys.exit(1)
class Buglump:
def __init__(self):
self.builder = gtk.Builder()
self.builder.add_from_file('glade7.glade')
self.builder.connect_signals(self)
self.window = self.builder.get_object('window1')
self.num_display = self.builder.get_object('label1')
self.window.show()
def on_button_clicked(self, widget, data=None):
self.current = self.num_display.get_text()
self.current = self.current + widget.get_label()
self.num_display.set_label(self.current)
def on_window1_destroy(self, object, data=None):
print 'quit with cancel'
gtk.main_quit()
if __name__ == "__main__":
main = Buglump()
gtk.main()
The on_button_clicked function will get the object from the User Data instead of the widget. This can be useful to pass other objects than the widget.
In this example the label of the button is obtained from the widget passed.
Next up is using a sqlite database to populate the ComboBox.