/Demo/tix/samples/Balloon.py

http://unladen-swallow.googlecode.com/ · Python · 68 lines · 36 code · 14 blank · 18 comment · 3 complexity · 78969d70ac0689d065d2d33dc86dd0a8 MD5 · raw file

  1. # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: Balloon.py 36560 2004-07-18 06:16:08Z tim_one $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "tixwidgets.py": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program.
  12. # This file demonstrates the use of the tixBalloon widget, which provides
  13. # a interesting way to give help tips about elements in your user interface.
  14. # Your can display the help message in a "balloon" and a status bar widget.
  15. #
  16. import Tix
  17. TCL_ALL_EVENTS = 0
  18. def RunSample (root):
  19. balloon = DemoBalloon(root)
  20. balloon.mainloop()
  21. balloon.destroy()
  22. class DemoBalloon:
  23. def __init__(self, w):
  24. self.root = w
  25. self.exit = -1
  26. z = w.winfo_toplevel()
  27. z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
  28. status = Tix.Label(w, width=40, relief=Tix.SUNKEN, bd=1)
  29. status.pack(side=Tix.BOTTOM, fill=Tix.Y, padx=2, pady=1)
  30. # Create two mysterious widgets that need balloon help
  31. button1 = Tix.Button(w, text='Something Unexpected',
  32. command=self.quitcmd)
  33. button2 = Tix.Button(w, text='Something Else Unexpected')
  34. button2['command'] = lambda w=button2: w.destroy()
  35. button1.pack(side=Tix.TOP, expand=1)
  36. button2.pack(side=Tix.TOP, expand=1)
  37. # Create the balloon widget and associate it with the widgets that we want
  38. # to provide tips for:
  39. b = Tix.Balloon(w, statusbar=status)
  40. b.bind_widget(button1, balloonmsg='Close Window',
  41. statusmsg='Press this button to close this window')
  42. b.bind_widget(button2, balloonmsg='Self-destruct button',
  43. statusmsg='Press this button and it will destroy itself')
  44. def quitcmd (self):
  45. self.exit = 0
  46. def mainloop(self):
  47. foundEvent = 1
  48. while self.exit < 0 and foundEvent > 0:
  49. foundEvent = self.root.tk.dooneevent(TCL_ALL_EVENTS)
  50. def destroy (self):
  51. self.root.destroy()
  52. if __name__ == '__main__':
  53. root = Tix.Tk()
  54. RunSample(root)