/Demo/tkinter/matt/dialog-box.py

http://unladen-swallow.googlecode.com/ · Python · 64 lines · 56 code · 3 blank · 5 comment · 0 complexity · 898ccb11e1f64912574d4a6dca252b6f MD5 · raw file

  1. from Tkinter import *
  2. from Dialog import Dialog
  3. # this shows how to create a new window with a button in it
  4. # that can create new windows
  5. class Test(Frame):
  6. def printit(self):
  7. print "hi"
  8. def makeWindow(self):
  9. """Create a top-level dialog with some buttons.
  10. This uses the Dialog class, which is a wrapper around the Tcl/Tk
  11. tk_dialog script. The function returns 0 if the user clicks 'yes'
  12. or 1 if the user clicks 'no'.
  13. """
  14. # the parameters to this call are as follows:
  15. d = Dialog(
  16. self, ## name of a toplevel window
  17. title="fred the dialog box",## title on the window
  18. text="click on a choice", ## message to appear in window
  19. bitmap="info", ## bitmap (if any) to appear;
  20. ## if none, use ""
  21. # legal values here are:
  22. # string what it looks like
  23. # ----------------------------------------------
  24. # error a circle with a slash through it
  25. # grey25 grey square
  26. # grey50 darker grey square
  27. # hourglass use for "wait.."
  28. # info a large, lower case "i"
  29. # questhead a human head with a "?" in it
  30. # question a large "?"
  31. # warning a large "!"
  32. # @fname X bitmap where fname is the path to the file
  33. #
  34. default=0, # the index of the default button choice.
  35. # hitting return selects this
  36. strings=("yes", "no"))
  37. # values of the 'strings' key are the labels for the
  38. # buttons that appear left to right in the dialog box
  39. return d.num
  40. def createWidgets(self):
  41. self.QUIT = Button(self, text='QUIT', foreground='red',
  42. command=self.quit)
  43. self.QUIT.pack(side=LEFT, fill=BOTH)
  44. # a hello button
  45. self.hi_there = Button(self, text='Make a New Window',
  46. command=self.makeWindow)
  47. self.hi_there.pack(side=LEFT)
  48. def __init__(self, master=None):
  49. Frame.__init__(self, master)
  50. Pack.config(self)
  51. self.windownum = 0
  52. self.createWidgets()
  53. test = Test()
  54. test.mainloop()