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 11__all__ = ["Dialog"] 12 13from tkinter import Frame, _get_temp_root, _destroy_temp_root 14 15 16class Dialog: 17 18 command = None 19 20 def __init__(self, master=None, **options): 21 if master is None: 22 master = options.get('parent') 23 self.master = master 24 self.options = options 25 26 def _fixoptions(self): 27 pass # hook 28 29 def _fixresult(self, widget, result): 30 return result # hook 31 32 def show(self, **options): 33 34 # update instance options 35 for k, v in options.items(): 36 self.options[k] = v 37 38 self._fixoptions() 39 40 master = self.master 41 if master is None: 42 master = _get_temp_root() 43 try: 44 self._test_callback(master) # The function below is replaced for some tests. 45 s = master.tk.call(self.command, *master._options(self.options)) 46 s = self._fixresult(master, s) 47 finally: 48 _destroy_temp_root(master) 49 50 return s 51 52 def _test_callback(self, master): 53 pass 54