Misc. changes, including documenting the ability to specify a class attribute in...
[python.git] / Lib / lib-tk / tkCommonDialog.py
blob2cd9be4eac0c8b20dae9ddb24933c62e538adcbd
1 # base class for tk common dialogues
3 # this module provides a base class for accessing the common
4 # dialogues available in Tk 4.2 and newer. use tkFileDialog,
5 # tkColorChooser, and tkMessageBox to access the individual
6 # dialogs.
8 # written by Fredrik Lundh, May 1997
11 from Tkinter import *
13 class Dialog:
15 command = None
17 def __init__(self, master=None, **options):
19 # FIXME: should this be placed on the module level instead?
20 if TkVersion < 4.2:
21 raise TclError, "this module requires Tk 4.2 or newer"
23 self.master = master
24 self.options = options
25 if not master and options.get('parent'):
26 self.master = options['parent']
28 def _fixoptions(self):
29 pass # hook
31 def _fixresult(self, widget, result):
32 return result # hook
34 def show(self, **options):
36 # update instance options
37 for k, v in options.items():
38 self.options[k] = v
40 self._fixoptions()
42 # we need a dummy widget to properly process the options
43 # (at least as long as we use Tkinter 1.63)
44 w = Frame(self.master)
46 try:
48 s = w.tk.call(self.command, *w._options(self.options))
50 s = self._fixresult(w, s)
52 finally:
54 try:
55 # get rid of the widget
56 w.destroy()
57 except:
58 pass
60 return s