pygtk helloworld

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
import pygtk, gtk
pygtk.require('2.0')
class Base:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(10)
self.button = gtk.Button("Hello World")
self.button.connect("clicked", self.hello, None)
self.button.connect_object("clicked", gtk.Widget.destroy,self.window)
self.window.add(self.button)
self.button.show()
self.window.show()
def hello(self, widget,data=None):
print "Hello World"
def delete_event(self, widget, event, data = None):
print "delete event occured"
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def main(self):
gtk.main()
print __name__
if __name__ == "__main__":
base = Base()