Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # this shows how to spawn off new windows at a button press |
| 4 | |
| 5 | class Test(Frame): |
| 6 | def printit(self): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 7 | print("hi") |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 8 | |
| 9 | def makeWindow(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 10 | fred = Toplevel() |
| 11 | fred.label = Label(fred, text="Here's a new window") |
| 12 | fred.label.pack() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 13 | |
| 14 | def createWidgets(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 15 | self.QUIT = Button(self, text='QUIT', foreground='red', |
| 16 | command=self.quit) |
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 | self.QUIT.pack(side=LEFT, fill=BOTH) |
| 19 | |
| 20 | # a hello button |
| 21 | self.hi_there = Button(self, text='Make a New Window', |
| 22 | command=self.makeWindow) |
| 23 | self.hi_there.pack(side=LEFT) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 24 | |
| 25 | def __init__(self, master=None): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 26 | Frame.__init__(self, master) |
| 27 | Pack.config(self) |
| 28 | self.createWidgets() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 29 | |
| 30 | test = Test() |
| 31 | test.mainloop() |