Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | |
| 4 | class Test(Frame): |
| 5 | def printit(self): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 6 | print(self.hi_there["command"]) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 7 | |
| 8 | def createWidgets(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 9 | # a hello button |
| 10 | self.QUIT = Button(self, text='QUIT', foreground='red', |
| 11 | command=self.quit) |
| 12 | self.QUIT.pack(side=LEFT, fill=BOTH) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 13 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 14 | self.hi_there = Button(self, text='Hello', |
| 15 | command=self.printit) |
| 16 | self.hi_there.pack(side=LEFT) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 17 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 18 | # note how Packer defaults to side=TOP |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 19 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 20 | self.guy2 = Button(self, text='button 2') |
| 21 | self.guy2.pack() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 22 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 23 | self.guy3 = Button(self, text='button 3') |
| 24 | self.guy3.pack() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 25 | |
| 26 | def __init__(self, master=None): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 27 | Frame.__init__(self, master) |
| 28 | Pack.config(self) |
| 29 | self.createWidgets() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 30 | |
| 31 | test = Test() |
| 32 | test.mainloop() |