1 # dialog.py -- Tkinter interface to the tk_dialog script.
2
3 from tkinter import _cnfmerge, Widget, TclError, Button, Pack
4
5 __all__ = ["Dialog"]
6
7 DIALOG_ICON = 'questhead'
8
9
10 class ESC[4;38;5;81mDialog(ESC[4;38;5;149mWidget):
11 def __init__(self, master=None, cnf={}, **kw):
12 cnf = _cnfmerge((cnf, kw))
13 self.widgetName = '__dialog__'
14 self._setup(master, cnf)
15 self.num = self.tk.getint(
16 self.tk.call(
17 'tk_dialog', self._w,
18 cnf['title'], cnf['text'],
19 cnf['bitmap'], cnf['default'],
20 *cnf['strings']))
21 try: Widget.destroy(self)
22 except TclError: pass
23
24 def destroy(self): pass
25
26
27 def _test():
28 d = Dialog(None, {'title': 'File Modified',
29 'text':
30 'File "Python.h" has been modified'
31 ' since the last time it was saved.'
32 ' Do you want to save it before'
33 ' exiting the application.',
34 'bitmap': DIALOG_ICON,
35 'default': 0,
36 'strings': ('Save File',
37 'Discard Changes',
38 'Return to Editor')})
39 print(d.num)
40
41
42 if __name__ == '__main__':
43 t = Button(None, {'text': 'Test',
44 'command': _test,
45 Pack: {}})
46 q = Button(None, {'text': 'Quit',
47 'command': t.quit,
48 Pack: {}})
49 t.mainloop()