Reputation: 1597
In many PyGTk tutorials, event handlers are defined like below.
window.connect("destroy", self.close)
button.connect("clicked", self.print_hello_world)
Is there any class encapsulating "destroy", "clicked" string literals as I want to access them as constants.
Upvotes: 0
Views: 39
Reputation: 773
In small apps, we may write code like this:
class MyApp():
def __init__(self):
self.win = Gtk.Window()
self.win.set_size_request(400, 300)
self.win.connect('destroy', self.on_app_exit)
btn = Gtk.Button("hello")
btn.connect('clicked', self.on_button_clicked)
def run(self):
self.win.show_all()
Gtk.main()
def on_app_exit(self, window):
// do something.
Gtk.main_quit()
def on_button_clicked(self, btn):
print('hello, world')
def main():
app = MyApp()
app.run()
if __name__ == '__main__':
main()
Upvotes: 2