[Tutor] critique my script!
Christopher Spears
cspears2002 at yahoo.com
Wed Jun 21 05:11:54 CEST 2006
I made the changes that Danny suggested to my script:
#!/usr/bin/python
import os, pygtk
pygtk.require('2.0')
import gtk
class View:
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def button_pressed(self, widget, data=None):
self.on_button_pressed()
def __init__(self,title, button_text):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title(title)
self.window.set_border_width(10)
self.window.connect("delete_event",
self.delete_event)
def do_nothing():
pass
self.on_button_pressed = do_nothing
self.box = gtk.HBox(False, 0)
self.window.add(self.box)
self.button = gtk.Button(button_text)
self.button.connect("clicked", self.button_pressed)
self.box.pack_start(self.button, True, True, 0)
self.button.show()
self.box.show()
self.window.show()
def main(self):
gtk.main()
if __name__ == "__main__":
view = View("Hello World!", "Press me please!")
#def print_getcwd():
#print os.getcwd()
def say_hello():
print "Hello World!"
view.on_button_pressed = say_hello
view.main()
I can apparently call the functions sometimes without
(). Why is that?
More information about the Tutor
mailing list