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

http://unladen-swallow.googlecode.com/ · Python · 31 lines · 21 code · 8 blank · 2 comment · 0 complexity · 49abfabc4aaff6ee418c04a3dde983e9 MD5 · raw file

  1. from Tkinter import *
  2. # this shows how to spawn off new windows at a button press
  3. class Test(Frame):
  4. def printit(self):
  5. print "hi"
  6. def makeWindow(self):
  7. fred = Toplevel()
  8. fred.label = Label(fred, text="Here's a new window")
  9. fred.label.pack()
  10. def createWidgets(self):
  11. self.QUIT = Button(self, text='QUIT', foreground='red',
  12. command=self.quit)
  13. self.QUIT.pack(side=LEFT, fill=BOTH)
  14. # a hello button
  15. self.hi_there = Button(self, text='Make a New Window',
  16. command=self.makeWindow)
  17. self.hi_there.pack(side=LEFT)
  18. def __init__(self, master=None):
  19. Frame.__init__(self, master)
  20. Pack.config(self)
  21. self.createWidgets()
  22. test = Test()
  23. test.mainloop()