Dialog.py 1.5 KB

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