ToolTip box

masterofpuppets 1 Tallied Votes 354 Views Share
from Tkinter import *
root = Tk()

tipwindow = None

# Creates a tooptip box for a widget.
def createToolTip( widget, text ):
    def enter( event ):
        global tipwindow
        x = y = 0
        if tipwindow or not text:
            return
        x, y, cx, cy = widget.bbox( "insert" )
        x += widget.winfo_rootx() + 27
        y += widget.winfo_rooty() + 27
        # Creates a toplevel window
        tipwindow = tw = Toplevel( widget )
        # Leaves only the label and removes the app window
        tw.wm_overrideredirect( 1 )
        tw.wm_geometry( "+%d+%d" % ( x, y ) )
        label = Label( tw, text = text, justify = LEFT,
                       background = "#ffffe0", relief = SOLID, borderwidth = 1,
                       font = ( "tahoma", "8", "normal" ) )
        label.pack( ipadx = 1 )
        
    def close( event ):
        global tipwindow
        tw = tipwindow
        tipwindow = None
        if tw:
            tw.destroy()
            
    widget.bind( "<Enter>", enter )
    widget.bind( "<Leave>", close )

b = Button( root, text = "Mouse over" ); b.pack()
createToolTip( b, "Mouse is over the button" )

mainloop()
Gribouillis commented: useful routine +14
I searched for the tooltip box in the forum and couldn't find a Python version for it.
So here's what I am using.

P.S I found it in google somewhere :)
richard.grigonis 0 Newbie Poster

I used this routine to add "balloon help" to a toolbar of icons. For Python 3.4 I simply had to make sure that Tkinter is lowercase: "tkinter" Ingeniously straightforward and simple. Bravo!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.