Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # this file demonstrates the creation of widgets as part of a canvas object |
| 4 | |
| 5 | class Test(Frame): |
| 6 | def printhi(self): |
| 7 | print "hi" |
| 8 | |
| 9 | def createWidgets(self): |
| 10 | self.QUIT = Button(self, {'text': 'QUIT', |
| 11 | 'fg': 'red', |
| 12 | 'command': self.quit}) |
| 13 | self.QUIT.pack({'side': 'bottom', 'fill': 'both'}) |
| 14 | |
| 15 | self.draw = Canvas(self, {"width" : "5i", "height" : "5i"}) |
| 16 | |
| 17 | self.button = Button(self, {"text" : "this is a button", |
| 18 | "command" : self.printhi}) |
| 19 | |
| 20 | # note here the coords are given in pixels (form the |
| 21 | # upper right and corner of the window, as usual for X) |
| 22 | # but might just have well been given in inches or points or |
| 23 | # whatever...use the "anchor" option to control what point of the |
| 24 | # widget (in this case the button) gets mapped to the given x, y. |
| 25 | # you can specify corners, edges, center, etc... |
| 26 | self.draw.create_window(300, 300, {"window" : self.button}) |
| 27 | |
| 28 | self.draw.pack({'side': 'left'}) |
| 29 | |
| 30 | |
| 31 | |
| 32 | def __init__(self, master=None): |
| 33 | Frame.__init__(self, master) |
| 34 | Pack.config(self) |
| 35 | self.createWidgets() |
| 36 | |
| 37 | test = Test() |
| 38 | |
| 39 | test.mainloop() |