Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # this is the same as simple-demo-1.py, but uses |
| 4 | # subclassing. |
| 5 | # note that there is no explicit call to start Tk. |
| 6 | # Tkinter is smart enough to start the system if it's not already going. |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | class Test(Frame): |
| 12 | def printit(self): |
| 13 | print "hi" |
| 14 | |
| 15 | def createWidgets(self): |
| 16 | self.QUIT = Button(self, {'text': 'QUIT', |
| 17 | 'fg': 'red', |
| 18 | 'command': self.quit}) |
| 19 | self.QUIT.pack({'side': 'bottom', 'fill': 'both'}) |
| 20 | |
| 21 | self.draw = Canvas(self, {"width" : "5i", "height" : "5i"}) |
| 22 | |
| 23 | self.speed = Scale(self, {"orient": "horiz", |
| 24 | "from" : -100, |
| 25 | "to" : 100}) |
| 26 | |
| 27 | self.speed.pack({'side': 'bottom', "fill" : "x"}) |
| 28 | |
| 29 | # all of these work.. |
| 30 | self.draw.create_polygon("0", "0", "10", "0", "10", "10", "0" , "10", {"tags" : "thing"}) |
| 31 | self.draw.pack({'side': 'left'}) |
| 32 | |
| 33 | def moveThing(self, *args): |
| 34 | velocity = self.speed.get() |
| 35 | str = float(velocity) / 1000.0 |
| 36 | str = `str` + "i" |
| 37 | self.draw.move("thing", str, str) |
| 38 | self.after(10, self.moveThing) |
| 39 | |
| 40 | |
| 41 | |
| 42 | def __init__(self, master=None): |
| 43 | Frame.__init__(self, master) |
| 44 | Pack.config(self) |
| 45 | self.createWidgets() |
| 46 | self.after(10, self.moveThing) |
| 47 | |
| 48 | |
| 49 | test = Test() |
| 50 | |
| 51 | test.mainloop() |