/Demo/tkinter/matt/window-creation-more.py

http://unladen-swallow.googlecode.com/ · Python · 35 lines · 25 code · 7 blank · 3 comment · 0 complexity · af9f0c0222bc2eea8946dc999f534a03 MD5 · raw file

  1. from Tkinter import *
  2. # this shows how to create a new window with a button in it
  3. # that can create new windows
  4. class Test(Frame):
  5. def printit(self):
  6. print "hi"
  7. def makeWindow(self):
  8. fred = Toplevel()
  9. fred.label = Button(fred,
  10. text="This is window number %d." % self.windownum,
  11. command=self.makeWindow)
  12. fred.label.pack()
  13. self.windownum = self.windownum + 1
  14. def createWidgets(self):
  15. self.QUIT = Button(self, text='QUIT', foreground='red',
  16. command=self.quit)
  17. self.QUIT.pack(side=LEFT, fill=BOTH)
  18. # a hello button
  19. self.hi_there = Button(self, text='Make a New Window',
  20. command=self.makeWindow)
  21. self.hi_there.pack(side=LEFT)
  22. def __init__(self, master=None):
  23. Frame.__init__(self, master)
  24. Pack.config(self)
  25. self.windownum = 0
  26. self.createWidgets()
  27. test = Test()
  28. test.mainloop()