Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 2 | from Dialog import Dialog |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 3 | |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 4 | # this shows how to create a new window with a button in it |
| 5 | # that can create new windows |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 6 | |
| 7 | class Test(Frame): |
| 8 | def printit(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 9 | print "hi" |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 10 | |
| 11 | def makeWindow(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 12 | """Create a top-level dialog with some buttons. |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 13 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 14 | This uses the Dialog class, which is a wrapper around the Tcl/Tk |
| 15 | tk_dialog script. The function returns 0 if the user clicks 'yes' |
| 16 | or 1 if the user clicks 'no'. |
| 17 | """ |
| 18 | # the parameters to this call are as follows: |
| 19 | d = Dialog( |
| 20 | self, ## name of a toplevel window |
| 21 | title="fred the dialog box",## title on the window |
| 22 | text="click on a choice", ## message to appear in window |
| 23 | bitmap="info", ## bitmap (if any) to appear; |
| 24 | ## if none, use "" |
| 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 X bitmap where fname is the path to the file |
| 37 | # |
| 38 | default=0, # the index of the default button choice. |
| 39 | # hitting return selects this |
| 40 | strings=("yes", "no")) |
| 41 | # values of the 'strings' key are the labels for the |
| 42 | # buttons that appear left to right in the dialog box |
| 43 | return d.num |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 44 | |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 45 | |
| 46 | def createWidgets(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 47 | self.QUIT = Button(self, text='QUIT', foreground='red', |
| 48 | command=self.quit) |
| 49 | self.QUIT.pack(side=LEFT, fill=BOTH) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 50 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 51 | # a hello button |
| 52 | self.hi_there = Button(self, text='Make a New Window', |
| 53 | command=self.makeWindow) |
| 54 | self.hi_there.pack(side=LEFT) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | def __init__(self, master=None): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 58 | Frame.__init__(self, master) |
| 59 | Pack.config(self) |
| 60 | self.windownum = 0 |
| 61 | self.createWidgets() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 62 | |
| 63 | test = Test() |
| 64 | test.mainloop() |