Ticket #5422: twgtk2helloworld.py

File twgtk2helloworld.py, 1.1 KB (added by frontendloader, 7 years ago)

twisted gtk2 "hello world" type example

Line 
1from twisted.internet import gtk2reactor
2gtk2reactor.install()
3#changes the type of reactor that is installed
4#see http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#auto11
5
6import gtk
7from twisted.internet import reactor
8
9class HelloWorld:
10        def hello(self, widge, data=None):
11                print "Hello World"
12       
13        def destroy(self, widget, data=None):
14                # stopping the reactor also stops the gtk.main() loop
15                # by calling gtk.main_quit()
16                reactor.stop()
17       
18        def delete_event(self, widget, event, data=None):
19                print "delete event occurred"
20                return False
21       
22        def __init__(self):
23                self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
24                self.window.connect("delete_event", self.delete_event)
25                self.window.connect("destroy", self.destroy)
26                self.window.set_border_width(10)
27                self.button = gtk.Button("Hello World")
28                self.button.connect("clicked", self.hello, None)
29                self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
30                self.window.add(self.button)
31                self.button.show()
32                self.window.show()     
33
34if __name__ == "__main__":
35        HelloWorld()
36        # since we've installed the gtk2reactor
37        # running our reactor will also start the gtk.main() loop
38        reactor.run()