• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# base class for tk common dialogues
2#
3# this module provides a base class for accessing the common
4# dialogues available in Tk 4.2 and newer.  use filedialog,
5# colorchooser, and messagebox to access the individual
6# dialogs.
7#
8# written by Fredrik Lundh, May 1997
9#
10
11from tkinter import *
12
13
14class Dialog:
15
16    command  = None
17
18    def __init__(self, master=None, **options):
19        self.master  = master
20        self.options = options
21        if not master and options.get('parent'):
22            self.master = options['parent']
23
24    def _fixoptions(self):
25        pass # hook
26
27    def _fixresult(self, widget, result):
28        return result # hook
29
30    def show(self, **options):
31
32        # update instance options
33        for k, v in options.items():
34            self.options[k] = v
35
36        self._fixoptions()
37
38        # we need a dummy widget to properly process the options
39        # (at least as long as we use Tkinter 1.63)
40        w = Frame(self.master)
41
42        try:
43
44            s = w.tk.call(self.command, *w._options(self.options))
45
46            s = self._fixresult(w, s)
47
48        finally:
49
50            try:
51                # get rid of the widget
52                w.destroy()
53            except:
54                pass
55
56        return s
57