| 1 | n/a | # dialog.py -- Tkinter interface to the tk_dialog script. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | from tkinter import * |
|---|
| 4 | n/a | from tkinter import _cnfmerge |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | DIALOG_ICON = 'questhead' |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | class Dialog(Widget): |
|---|
| 10 | n/a | def __init__(self, master=None, cnf={}, **kw): |
|---|
| 11 | n/a | cnf = _cnfmerge((cnf, kw)) |
|---|
| 12 | n/a | self.widgetName = '__dialog__' |
|---|
| 13 | n/a | Widget._setup(self, master, cnf) |
|---|
| 14 | n/a | self.num = self.tk.getint( |
|---|
| 15 | n/a | self.tk.call( |
|---|
| 16 | n/a | 'tk_dialog', self._w, |
|---|
| 17 | n/a | cnf['title'], cnf['text'], |
|---|
| 18 | n/a | cnf['bitmap'], cnf['default'], |
|---|
| 19 | n/a | *cnf['strings'])) |
|---|
| 20 | n/a | try: Widget.destroy(self) |
|---|
| 21 | n/a | except TclError: pass |
|---|
| 22 | n/a | def destroy(self): pass |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | def _test(): |
|---|
| 25 | n/a | d = Dialog(None, {'title': 'File Modified', |
|---|
| 26 | n/a | 'text': |
|---|
| 27 | n/a | 'File "Python.h" has been modified' |
|---|
| 28 | n/a | ' since the last time it was saved.' |
|---|
| 29 | n/a | ' Do you want to save it before' |
|---|
| 30 | n/a | ' exiting the application.', |
|---|
| 31 | n/a | 'bitmap': DIALOG_ICON, |
|---|
| 32 | n/a | 'default': 0, |
|---|
| 33 | n/a | 'strings': ('Save File', |
|---|
| 34 | n/a | 'Discard Changes', |
|---|
| 35 | n/a | 'Return to Editor')}) |
|---|
| 36 | n/a | print(d.num) |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | if __name__ == '__main__': |
|---|
| 40 | n/a | t = Button(None, {'text': 'Test', |
|---|
| 41 | n/a | 'command': _test, |
|---|
| 42 | n/a | Pack: {}}) |
|---|
| 43 | n/a | q = Button(None, {'text': 'Quit', |
|---|
| 44 | n/a | 'command': t.quit, |
|---|
| 45 | n/a | Pack: {}}) |
|---|
| 46 | n/a | t.mainloop() |
|---|