Home | History | Annotate | Download | only in tkinter
      1 # dialog.py -- Tkinter interface to the tk_dialog script.
      2 
      3 from tkinter import *
      4 from tkinter import _cnfmerge
      5 
      6 DIALOG_ICON = 'questhead'
      7 
      8 
      9 class 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     def destroy(self): pass
     23 
     24 def _test():
     25     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')})
     36     print(d.num)
     37 
     38 
     39 if __name__ == '__main__':
     40     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()
     47