dialog.py 1.5 KB

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