« »

Python:TKinter的几种对话框

Quitter,dialogTable,demoDlg

  1. #quitter.py
  2. from Tkinter import *                          # get widget classes
  3. from tkMessageBox import askokcancel           # get canned std dialog
  4.  
  5. class Quitter(Frame):                          # subclass our GUI
  6.     def _ _init_ _(self, parent=None):             # constructor method
  7.         Frame._ _init_ _(self, parent)
  8.         self.pack( )
  9.         widget = Button(self, text='Quit', command=self.quit)
  10.         widget.pack(side=LEFT)
  11.     def quit(self):
  12.         ans = askokcancel('Verify exit', "Really quit?")
  13.         if ans: Frame.quit(self)
  14.  
  15. if _ _name_ _ == '_ _main_ _'Quitter().mainloop( )
  16.  
  17. #dialogTable.py
  18. # define a name:callback demos table
  19.  
  20. from tkFileDialog   import askopenfilename        # get standard dialogs
  21. from tkColorChooser import askcolor               # they live in Lib/lib-tk
  22. from tkMessageBox   import askquestion, showerror
  23. from tkSimpleDialog import askfloat
  24.  
  25. demos = {
  26.     'Open'askopenfilename,
  27.     'Color': askcolor,
  28.     'Query': lambda: askquestion('Warning', 'You typed "rm *"\nConfirm?'),
  29.     'Error': lambda: showerror('Error!', "He's dead, Jim"),
  30.     'Input': lambda: askfloat('Entry', 'Enter credit card number')
  31. }
  32. #demoDlg.py
  33. from Tkinter import *              # get base widget set
  34. from dialogTable import demos      # button callback handlers
  35. from quitter import Quitter        # attach a quit object to me
  36.  
  37. class Demo(Frame):
  38.     def _ _init_ _(self, parent=None):
  39.         Frame._ _init_ _(self, parent)
  40.         self.pack( )
  41.         Label(self, text="Basic demos").pack( )
  42.         for (key, value) in demos.items( ):
  43.             Button(self, text=key, command=value).pack(side=TOP, fill=BOTH)
  44.         Quitter(self).pack(side=TOP, fill=BOTH)
  45.  
  46. if _ _name_ _ == '_ _main_ _': Demo().mainloop( )

您还可能感兴趣的内容

日志信息 »

该日志于2008-08-21 16:07由 x72 发表在Python分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »


返回顶部