dialog.py 1.53 KB
Newer Older
1
# dialog.py -- Tkinter interface to the tk_dialog script.
2

3 4
from tkinter import *
from tkinter import _cnfmerge
Guido van Rossum's avatar
Guido van Rossum committed
5

6
if TkVersion <= 3.6:
7
    DIALOG_ICON = 'warning'
8
else:
9
    DIALOG_ICON = 'questhead'
10 11


Guido van Rossum's avatar
Guido van Rossum committed
12
class Dialog(Widget):
13 14 15 16 17
    def __init__(self, master=None, cnf={}, **kw):
        cnf = _cnfmerge((cnf, kw))
        self.widgetName = '__dialog__'
        Widget._setup(self, master, cnf)
        self.num = self.tk.getint(
18 19 20 21 22
                self.tk.call(
                      'tk_dialog', self._w,
                      cnf['title'], cnf['text'],
                      cnf['bitmap'], cnf['default'],
                      *cnf['strings']))
23 24 25
        try: Widget.destroy(self)
        except TclError: pass
    def destroy(self): pass
Guido van Rossum's avatar
Guido van Rossum committed
26 27

def _test():
28 29 30 31 32 33 34 35 36 37 38
    d = Dialog(None, {'title': 'File Modified',
                      'text':
                      'File "Python.h" has been modified'
                      ' since the last time it was saved.'
                      ' Do you want to save it before'
                      ' exiting the application.',
                      'bitmap': DIALOG_ICON,
                      'default': 0,
                      'strings': ('Save File',
                                  'Discard Changes',
                                  'Return to Editor')})
39
    print(d.num)
Guido van Rossum's avatar
Guido van Rossum committed
40 41 42


if __name__ == '__main__':
43 44 45 46 47 48 49
    t = Button(None, {'text': 'Test',
                      'command': _test,
                      Pack: {}})
    q = Button(None, {'text': 'Quit',
                      'command': t.quit,
                      Pack: {}})
    t.mainloop()