blob: db8f5dabc0f006f24f1af566edf8e2b053ef57ab [file] [log] [blame]
Guido van Rossumf7132471994-06-27 08:00:16 +00001# Dialog.py -- Tkinter interface to the tk_dialog script.
Guido van Rossum761c5ab1995-07-14 15:29:10 +00002
Guido van Rossumf7132471994-06-27 08:00:16 +00003from Tkinter import *
4
Guido van Rossum761c5ab1995-07-14 15:29:10 +00005if TkVersion == 3.6:
6 DIALOG_ICON = 'warning'
7else:
8 DIALOG_ICON = 'questhead'
9
10
Guido van Rossumf7132471994-06-27 08:00:16 +000011class Dialog(Widget):
12 def __init__(self, master=None, cnf={}):
Guido van Rossum761c5ab1995-07-14 15:29:10 +000013 self.widgetName = '__dialog__'
Guido van Rossumf7132471994-06-27 08:00:16 +000014 Widget._setup(self, master, cnf)
Guido van Rossumf023ab01994-08-30 12:13:44 +000015 self.num = self.tk.getint(
16 apply(self.tk.call,
17 ('tk_dialog', self._w,
18 cnf['title'], cnf['text'],
19 cnf['bitmap'], cnf['default'])
20 + cnf['strings']))
Guido van Rossumf7132471994-06-27 08:00:16 +000021 try: Widget.destroy(self)
22 except TclError: pass
23 def destroy(self): pass
24
25def _test():
26 d = Dialog(None, {'title': 'File Modified',
27 'text':
28 'File "Python.h" has been modified'
29 ' since the last time it was saved.'
30 ' Do you want to save it before'
31 ' exiting the application.',
Guido van Rossum761c5ab1995-07-14 15:29:10 +000032 'bitmap': DIALOG_ICON,
Guido van Rossumf7132471994-06-27 08:00:16 +000033 'default': 0,
34 'strings': ('Save File',
35 'Discard Changes',
36 'Return to Editor')})
37 print d.num
38
39
40if __name__ == '__main__':
41 t = Button(None, {'text': 'Test',
42 'command': _test,
43 Pack: {}})
44 q = Button(None, {'text': 'Quit',
45 'command': t.quit,
46 Pack: {}})
47 t.mainloop()