We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

The wckToolTips Module

Fredrik Lundh | September 2007

The wckToolTips lets you add tooltips (aka “balloon help”) to arbitrary Tkinter widgets (including WCK widgets).

This implementation is light-weight and relatively non-intrusive; it uses a single global tooltip controller for all widgets, which is attached via a custom binding class (bindtags), and adds a single attribute reference to the target widget.

Installation

You can get the module from the effbot.org WCK sandbox:

http://svn.effbot.org/public/stuff/sandbox/wcklib/

Note that despite the name, this module does not depend on the WCK library. You can still use it with WCK widgets, of course.

Usage

To add a tooltip to a widget, just call the register method with the widget and the tip text:

from Tkinter import *
import wckToolTips

root = Tk()

b = Button(root, text="Click me!", command=root.quit)
b.pack()

wckToolTips.register(b, "This button exits the program")

mainloop()

There’s no need to unregister the text; the tooltip information is automatically discarded when the widget is destroyed. If you want to explicitly unregister the text from an existing widget, use the unregister method.

You can use a callback instead of a text string. The callback is called with the target widget and the mouse coordinates, and should return a string:

...

def help(widget, position):
    import time
    return "The time is " + time.asctime()

wckToolTips.register(b, help)

Note that the callback is called once for each time a tip is displayed for a given widget; there’s currently no way to update the text if the user moves the mouse pointer around inside the widget itself, without moving it out of the widget.