blob: cb463f717c0e4c97d982fb6f899686b8fb3ea9f3 [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
Serhiy Storchakadc0d5712018-10-12 19:01:00 +030022
Fred Draked038ca82000-10-23 18:31:14 +000023 def destroy(self): pass
Guido van Rossumf7132471994-06-27 08:00:16 +000024
Serhiy Storchakadc0d5712018-10-12 19:01:00 +030025
Guido van Rossumf7132471994-06-27 08:00:16 +000026def _test():
Fred Draked038ca82000-10-23 18:31:14 +000027 d = Dialog(None, {'title': 'File Modified',
28 'text':
29 'File "Python.h" has been modified'
30 ' since the last time it was saved.'
31 ' Do you want to save it before'
32 ' exiting the application.',
33 'bitmap': DIALOG_ICON,
34 'default': 0,
35 'strings': ('Save File',
36 'Discard Changes',
37 'Return to Editor')})
Guido van Rossumbe19ed72007-02-09 05:37:30 +000038 print(d.num)
Guido van Rossumf7132471994-06-27 08:00:16 +000039
40
41if __name__ == '__main__':
Fred Draked038ca82000-10-23 18:31:14 +000042 t = Button(None, {'text': 'Test',
43 'command': _test,
44 Pack: {}})
45 q = Button(None, {'text': 'Quit',
46 'command': t.quit,
47 Pack: {}})
48 t.mainloop()