943,487 Members | Top Members by Rank

Ad:
  • Python Code Snippet
  • Views: 2331
  • Python RSS
0

ToolTip box

by on Oct 31st, 2009
Python Syntax (Toggle Plain Text)
  1. from Tkinter import *
  2. root = Tk()
  3.  
  4. tipwindow = None
  5.  
  6. # Creates a tooptip box for a widget.
  7. def createToolTip( widget, text ):
  8. def enter( event ):
  9. global tipwindow
  10. x = y = 0
  11. if tipwindow or not text:
  12. return
  13. x, y, cx, cy = widget.bbox( "insert" )
  14. x += widget.winfo_rootx() + 27
  15. y += widget.winfo_rooty() + 27
  16. # Creates a toplevel window
  17. tipwindow = tw = Toplevel( widget )
  18. # Leaves only the label and removes the app window
  19. tw.wm_overrideredirect( 1 )
  20. tw.wm_geometry( "+%d+%d" % ( x, y ) )
  21. label = Label( tw, text = text, justify = LEFT,
  22. background = "#ffffe0", relief = SOLID, borderwidth = 1,
  23. font = ( "tahoma", "8", "normal" ) )
  24. label.pack( ipadx = 1 )
  25.  
  26. def close( event ):
  27. global tipwindow
  28. tw = tipwindow
  29. tipwindow = None
  30. if tw:
  31. tw.destroy()
  32.  
  33. widget.bind( "<Enter>", enter )
  34. widget.bind( "<Leave>", close )
  35.  
  36. b = Button( root, text = "Mouse over" ); b.pack()
  37. createToolTip( b, "Mouse is over the button" )
  38.  
  39. mainloop()
Python Code Snippet (Toggle Plain Text)
  1. I searched for the tooltip box in the forum and couldn't find a Python version for it.
  2. So here's what I am using.
  3.  
  4. P.S I found it in google somewhere :)
Message:
Previous Thread in Python Forum Timeline: Distinct Vlaues
Next Thread in Python Forum Timeline: Line number in Tkinter Text field





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC