blob: f61c5f7fa9ba0336c5fc7f19643eca22bd61e200 [file] [log] [blame]
Georg Brandl14fc4272008-05-17 18:39:55 +00001# dialog.py -- Tkinter interface to the tk_dialog script.
Guido van Rossum761c5ab1995-07-14 15:29:10 +00002
Georg Brandl14fc4272008-05-17 18:39:55 +00003from tkinter import *
4from tkinter import _cnfmerge
Guido van Rossumf7132471994-06-27 08:00:16 +00005
Serhiy Storchaka159e5352016-04-25 13:49:11 +03006DIALOG_ICON = 'questhead'
Guido van Rossum761c5ab1995-07-14 15:29:10 +00007
8
Guido van Rossumf7132471994-06-27 08:00:16 +00009class Dialog(Widget):
Fred Draked038ca82000-10-23 18:31:14 +000010 def __init__(self, master=None, cnf={}, **kw):
11 cnf = _cnfmerge((cnf, kw))
12 self.widgetName = '__dialog__'
13 Widget._setup(self, master, cnf)
14 self.num = self.tk.getint(
Raymond Hettingerff41c482003-04-06 09:01:11 +000015 self.tk.call(
16 'tk_dialog', self._w,
17 cnf['title'], cnf['text'],
18 cnf['bitmap'], cnf['default'],
19 *cnf['strings']))
Fred Draked038ca82000-10-23 18:31:14 +000020 try: Widget.destroy(self)
21 except TclError: pass
22 def destroy(self): pass
Guido van Rossumf7132471994-06-27 08:00:16 +000023
24def _test():
Fred Draked038ca82000-10-23 18:31:14 +000025 d = Dialog(None, {'title': 'File Modified',
26 'text':
27 'File "Python.h" has been modified'
28 ' since the last time it was saved.'
29 ' Do you want to save it before'
30 ' exiting the application.',
31 'bitmap': DIALOG_ICON,
32 'default': 0,
33 'strings': ('Save File',
34 'Discard Changes',
35 'Return to Editor')})
Guido van Rossumbe19ed72007-02-09 05:37:30 +000036 print(d.num)
Guido van Rossumf7132471994-06-27 08:00:16 +000037
38
39if __name__ == '__main__':
Fred Draked038ca82000-10-23 18:31:14 +000040 t = Button(None, {'text': 'Test',
41 'command': _test,
42 Pack: {}})
43 q = Button(None, {'text': 'Quit',
44 'command': t.quit,
45 Pack: {}})
46 t.mainloop()