blob: b52e5b49d292c2f12f1bed3feedf52ee2df1b4a0 [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 *
Guido van Rossum94550631995-08-04 03:49:39 +00004from Tkinter import _cnfmerge
Guido van Rossumf7132471994-06-27 08:00:16 +00005
Guido van Rossum94550631995-08-04 03:49:39 +00006if TkVersion <= 3.6:
Fred Draked038ca82000-10-23 18:31:14 +00007 DIALOG_ICON = 'warning'
Guido van Rossum761c5ab1995-07-14 15:29:10 +00008else:
Fred Draked038ca82000-10-23 18:31:14 +00009 DIALOG_ICON = 'questhead'
Guido van Rossum761c5ab1995-07-14 15:29:10 +000010
11
Guido van Rossumf7132471994-06-27 08:00:16 +000012class Dialog(Widget):
Fred Draked038ca82000-10-23 18:31:14 +000013 def __init__(self, master=None, cnf={}, **kw):
14 cnf = _cnfmerge((cnf, kw))
15 self.widgetName = '__dialog__'
16 Widget._setup(self, master, cnf)
17 self.num = self.tk.getint(
Raymond Hettingerff41c482003-04-06 09:01:11 +000018 self.tk.call(
19 'tk_dialog', self._w,
20 cnf['title'], cnf['text'],
21 cnf['bitmap'], cnf['default'],
22 *cnf['strings']))
Fred Draked038ca82000-10-23 18:31:14 +000023 try: Widget.destroy(self)
24 except TclError: pass
25 def destroy(self): pass
Guido van Rossumf7132471994-06-27 08:00:16 +000026
27def _test():
Fred Draked038ca82000-10-23 18:31:14 +000028 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
Guido van Rossumf7132471994-06-27 08:00:16 +000040
41
42if __name__ == '__main__':
Fred Draked038ca82000-10-23 18:31:14 +000043 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()