Dialog.py 1.54 KB
Newer Older
Guido van Rossum's avatar
Guido van Rossum committed
1
# Dialog.py -- Tkinter interface to the tk_dialog script.
2

Guido van Rossum's avatar
Guido van Rossum committed
3
from Tkinter import *
4
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 18 19 20 21 22 23 24 25
    def __init__(self, master=None, cnf={}, **kw):
        cnf = _cnfmerge((cnf, kw))
        self.widgetName = '__dialog__'
        Widget._setup(self, master, cnf)
        self.num = self.tk.getint(
                apply(self.tk.call,
                      ('tk_dialog', self._w,
                       cnf['title'], cnf['text'],
                       cnf['bitmap'], cnf['default'])
                      + cnf['strings']))
        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 39
    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')})
    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()