Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame^] | 1 | from Tkinter import * |
| 2 | |
| 3 | # this shows how to create a new window with a button in it that can create new windows |
| 4 | |
| 5 | class Test(Frame): |
| 6 | def printit(self): |
| 7 | print "hi" |
| 8 | |
| 9 | def makeWindow(self): |
| 10 | # there is no Tkinter interface to the dialog box. Making one would mean putting |
| 11 | # a few wrapper functions in the Tkinter.py file. |
| 12 | # even better is to put in a SUIT-like selection of commonly-used dialogs. |
| 13 | # the parameters to this call are as follows: |
| 14 | |
| 15 | fred = Toplevel() # a toplevel window that the dialog goes into |
| 16 | |
| 17 | |
| 18 | # this function returns the index of teh button chosen. In this case, 0 for "yes" and 1 for "no" |
| 19 | |
| 20 | print self.tk.call("tk_dialog", # the command name |
| 21 | fred, # the name of a toplevel window |
| 22 | "fred the dialog box", # the title on the window |
| 23 | "click on a choice", # the message to appear in the window |
| 24 | "info", # the bitmap (if any) to appear. If no bitmap is desired, pass "" |
| 25 | # legal values here are: |
| 26 | # string what it looks like |
| 27 | # ---------------------------------------------- |
| 28 | # error a circle with a slash through it |
| 29 | # grey25 grey square |
| 30 | # grey50 darker grey square |
| 31 | # hourglass use for "wait.." |
| 32 | # info a large, lower case "i" |
| 33 | # questhead a human head with a "?" in it |
| 34 | # question a large "?" |
| 35 | # warning a large "!" |
| 36 | # @fname any X bitmap where fname is the path to the file |
| 37 | # |
| 38 | "0", # the index of the default button choice. hitting return selects this |
| 39 | "yes", "no") # all remaining parameters are the labels for the |
| 40 | # buttons that appear left to right in the dialog box |
| 41 | |
| 42 | |
| 43 | |
| 44 | def createWidgets(self): |
| 45 | self.QUIT = Button(self, {'text': 'QUIT', |
| 46 | 'fg': 'red', |
| 47 | 'command': self.quit}) |
| 48 | |
| 49 | self.QUIT.pack({'side': 'left', 'fill': 'both'}) |
| 50 | |
| 51 | |
| 52 | # a hello button |
| 53 | self.hi_there = Button(self, {'text': 'Make a New Window', |
| 54 | 'command' : self.makeWindow}) |
| 55 | self.hi_there.pack({'side': 'left'}) |
| 56 | |
| 57 | |
| 58 | def __init__(self, master=None): |
| 59 | Frame.__init__(self, master) |
| 60 | Pack.config(self) |
| 61 | self.windownum = 0 |
| 62 | self.createWidgets() |
| 63 | |
| 64 | test = Test() |
| 65 | test.mainloop() |