Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 1 | # Dialog.py -- Tkinter interface to the tk_dialog script. |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 3 | from Tkinter import * |
Guido van Rossum | 9455063 | 1995-08-04 03:49:39 +0000 | [diff] [blame] | 4 | from Tkinter import _cnfmerge |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | 9455063 | 1995-08-04 03:49:39 +0000 | [diff] [blame] | 6 | if TkVersion <= 3.6: |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 7 | DIALOG_ICON = 'warning' |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 8 | else: |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 9 | DIALOG_ICON = 'questhead' |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 10 | |
| 11 | |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 12 | class Dialog(Widget): |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 13 | 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 Hettinger | ff41c48 | 2003-04-06 09:01:11 +0000 | [diff] [blame] | 18 | self.tk.call( |
| 19 | 'tk_dialog', self._w, |
| 20 | cnf['title'], cnf['text'], |
| 21 | cnf['bitmap'], cnf['default'], |
| 22 | *cnf['strings'])) |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 23 | try: Widget.destroy(self) |
| 24 | except TclError: pass |
| 25 | def destroy(self): pass |
Guido van Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 26 | |
| 27 | def _test(): |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 28 | 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 Rossum | f713247 | 1994-06-27 08:00:16 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
Fred Drake | d038ca8 | 2000-10-23 18:31:14 +0000 | [diff] [blame] | 43 | 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() |