• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from Tkinter import *
2
3import sys
4##sys.path.append("/users/mjc4y/projects/python/tkinter/utils")
5##from TkinterUtils  import *
6
7# this shows how to create a new window with a button in it that
8# can create new windows
9
10class QuitButton(Button):
11    def __init__(self, master, *args, **kwargs):
12        if not kwargs.has_key("text"):
13            kwargs["text"] = "QUIT"
14        if not kwargs.has_key("command"):
15            kwargs["command"] = master.quit
16        apply(Button.__init__, (self, master) + args, kwargs)
17
18class Test(Frame):
19    def makeWindow(self, *args):
20        fred = Toplevel()
21
22        fred.label = Canvas (fred, width="2i", height="2i")
23
24        fred.label.create_line("0", "0", "2i", "2i")
25        fred.label.create_line("0", "2i", "2i", "0")
26        fred.label.pack()
27
28        ##centerWindow(fred, self.master)
29
30    def createWidgets(self):
31        self.QUIT = QuitButton(self)
32        self.QUIT.pack(side=LEFT, fill=BOTH)
33
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)
38
39    def __init__(self, master=None):
40        Frame.__init__(self, master)
41        Pack.config(self)
42        self.createWidgets()
43
44test = Test()
45test.mainloop()
46