1# dialog.py -- Tkinter interface to the tk_dialog script. 2 3from tkinter import * 4from tkinter import _cnfmerge 5 6DIALOG_ICON = 'questhead' 7 8 9class Dialog(Widget): 10 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( 15 self.tk.call( 16 'tk_dialog', self._w, 17 cnf['title'], cnf['text'], 18 cnf['bitmap'], cnf['default'], 19 *cnf['strings'])) 20 try: Widget.destroy(self) 21 except TclError: pass 22 23 def destroy(self): pass 24 25 26def _test(): 27 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')}) 38 print(d.num) 39 40 41if __name__ == '__main__': 42 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() 49