blob: 3a4ce195f69187c49803aa2df4c15afe407fb0c4 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
Guido van Rossum89cb67b1996-07-30 18:57:18 +00003# this shows how to create a new window with a button in it
4# that can create new windows
Guido van Rossum35820f71994-10-07 09:55:26 +00005
6class Test(Frame):
7 def printit(self):
Collin Winter6f2df4d2007-07-17 20:59:35 +00008 print("hi")
Guido van Rossum35820f71994-10-07 09:55:26 +00009
10 def makeWindow(self):
Tim Peters182b5ac2004-07-18 06:16:08 +000011 fred = Toplevel()
12 fred.label = Button(fred,
13 text="This is window number %d." % self.windownum,
14 command=self.makeWindow)
15 fred.label.pack()
16 self.windownum = self.windownum + 1
Guido van Rossum35820f71994-10-07 09:55:26 +000017
18 def createWidgets(self):
Tim Peters182b5ac2004-07-18 06:16:08 +000019 self.QUIT = Button(self, text='QUIT', foreground='red',
20 command=self.quit)
21 self.QUIT.pack(side=LEFT, fill=BOTH)
Guido van Rossum35820f71994-10-07 09:55:26 +000022
Tim Peters182b5ac2004-07-18 06:16:08 +000023 # a hello button
24 self.hi_there = Button(self, text='Make a New Window',
25 command=self.makeWindow)
26 self.hi_there.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000027
28 def __init__(self, master=None):
Tim Peters182b5ac2004-07-18 06:16:08 +000029 Frame.__init__(self, master)
30 Pack.config(self)
31 self.windownum = 0
32 self.createWidgets()
Guido van Rossum35820f71994-10-07 09:55:26 +000033
34test = Test()
35test.mainloop()