blob: dea8f39007cd970bfacede788c4a6fae1d195960 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
Guido van Rossum89cb67b1996-07-30 18:57:18 +00002from Dialog import Dialog
Guido van Rossum35820f71994-10-07 09:55:26 +00003
Guido van Rossum89cb67b1996-07-30 18:57:18 +00004# this shows how to create a new window with a button in it
5# that can create new windows
Guido van Rossum35820f71994-10-07 09:55:26 +00006
7class Test(Frame):
8 def printit(self):
Tim Peters182b5ac2004-07-18 06:16:08 +00009 print "hi"
Guido van Rossum35820f71994-10-07 09:55:26 +000010
11 def makeWindow(self):
Tim Peters182b5ac2004-07-18 06:16:08 +000012 """Create a top-level dialog with some buttons.
Guido van Rossum89cb67b1996-07-30 18:57:18 +000013
Tim Peters182b5ac2004-07-18 06:16:08 +000014 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 Rossum35820f71994-10-07 09:55:26 +000044
Guido van Rossum35820f71994-10-07 09:55:26 +000045
46 def createWidgets(self):
Tim Peters182b5ac2004-07-18 06:16:08 +000047 self.QUIT = Button(self, text='QUIT', foreground='red',
48 command=self.quit)
49 self.QUIT.pack(side=LEFT, fill=BOTH)
Guido van Rossum35820f71994-10-07 09:55:26 +000050
Tim Peters182b5ac2004-07-18 06:16:08 +000051 # 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 Rossum35820f71994-10-07 09:55:26 +000055
56
57 def __init__(self, master=None):
Tim Peters182b5ac2004-07-18 06:16:08 +000058 Frame.__init__(self, master)
59 Pack.config(self)
60 self.windownum = 0
61 self.createWidgets()
Guido van Rossum35820f71994-10-07 09:55:26 +000062
63test = Test()
64test.mainloop()