Python:TKinter的几种对话框
Quitter,dialogTable,demoDlg
- #quitter.py
- from Tkinter import * # get widget classes
- from tkMessageBox import askokcancel # get canned std dialog
- class Quitter(Frame): # subclass our GUI
- def _ _init_ _(self, parent=None): # constructor method
- Frame._ _init_ _(self, parent)
- self.pack( )
- widget = Button(self, text='Quit', command=self.quit)
- widget.pack(side=LEFT)
- def quit(self):
- ans = askokcancel('Verify exit', "Really quit?")
- if ans: Frame.quit(self)
- if _ _name_ _ == '_ _main_ _': Quitter().mainloop( )
- #dialogTable.py
- # define a name:callback demos table
- from tkFileDialog import askopenfilename # get standard dialogs
- from tkColorChooser import askcolor # they live in Lib/lib-tk
- from tkMessageBox import askquestion, showerror
- from tkSimpleDialog import askfloat
- demos = {
- 'Open': askopenfilename,
- 'Color': askcolor,
- 'Query': lambda: askquestion('Warning', 'You typed "rm *"\nConfirm?'),
- 'Error': lambda: showerror('Error!', "He's dead, Jim"),
- 'Input': lambda: askfloat('Entry', 'Enter credit card number')
- }
- #demoDlg.py
- from Tkinter import * # get base widget set
- from dialogTable import demos # button callback handlers
- from quitter import Quitter # attach a quit object to me
- class Demo(Frame):
- def _ _init_ _(self, parent=None):
- Frame._ _init_ _(self, parent)
- self.pack( )
- Label(self, text="Basic demos").pack( )
- for (key, value) in demos.items( ):
- Button(self, text=key, command=value).pack(side=TOP, fill=BOTH)
- Quitter(self).pack(side=TOP, fill=BOTH)
- if _ _name_ _ == '_ _main_ _': Demo().mainloop( )
没有评论▼