Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | import sys |
Guido van Rossum | 60cc90e | 1999-04-08 15:18:12 +0000 | [diff] [blame] | 4 | ##sys.path.append("/users/mjc4y/projects/python/tkinter/utils") |
| 5 | ##from TkinterUtils import * |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 7 | # this shows how to create a new window with a button in it that |
| 8 | # can create new windows |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 9 | |
Guido van Rossum | 60cc90e | 1999-04-08 15:18:12 +0000 | [diff] [blame] | 10 | class QuitButton(Button): |
| 11 | def __init__(self, master, *args, **kwargs): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 12 | if "text" not in kwargs: |
Guido van Rossum | 60cc90e | 1999-04-08 15:18:12 +0000 | [diff] [blame] | 13 | kwargs["text"] = "QUIT" |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 14 | if "command" not in kwargs: |
Guido van Rossum | 60cc90e | 1999-04-08 15:18:12 +0000 | [diff] [blame] | 15 | kwargs["command"] = master.quit |
Neal Norwitz | d910855 | 2006-03-17 08:00:19 +0000 | [diff] [blame] | 16 | Button.__init__(self, master, *args, **kwargs) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 17 | |
| 18 | class Test(Frame): |
| 19 | def makeWindow(self, *args): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 20 | fred = Toplevel() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 21 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 22 | fred.label = Canvas (fred, width="2i", height="2i") |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 23 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 24 | fred.label.create_line("0", "0", "2i", "2i") |
| 25 | fred.label.create_line("0", "2i", "2i", "0") |
| 26 | fred.label.pack() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 27 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 28 | ##centerWindow(fred, self.master) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 29 | |
| 30 | def createWidgets(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 31 | self.QUIT = QuitButton(self) |
| 32 | self.QUIT.pack(side=LEFT, fill=BOTH) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 33 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 34 | self.makeWindow = Button(self, text='Make a New Window', |
| 35 | width=50, height=20, |
| 36 | command=self.makeWindow) |
| 37 | self.makeWindow.pack(side=LEFT) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 38 | |
| 39 | def __init__(self, master=None): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 40 | Frame.__init__(self, master) |
| 41 | Pack.config(self) |
| 42 | self.createWidgets() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 43 | |
| 44 | test = Test() |
| 45 | test.mainloop() |