util.tooltip module

Inheritance diagram of CreateToolTip

tk_ToolTip_class101.py gives a Tkinter widget a tooltip as the mouse is above the widget tested with Python27 and Python34 by vegaseat 09sep2014 www.daniweb.com/programming/software-development/code/484591/a-tooltip-class-for-tkinter

Modified to include a delay time by Victor Zaccardo, 25mar16


util.tooltip.findCanvas(widget: Widget) → Canvas | None

Walks up the Tk widget hierarchy from widget looking for an enclosing tk.Canvas. Works for any widget embedded via canvas.create_window(…), since Tk requires such a widget’s master to already be (or descend from) the canvas it’s embedded in.

Parameters:

widget (tk.Widget) – The widget to search upward from.

Returns:

The nearest enclosing tk.Canvas, or None if there isn’t one.

Return type:

Optional[tk.Canvas]

class util.tooltip.CreateToolTip(widget: Widget, text: str | Callable[[], str] = '', canvasID: int | None = None, waitTime: int = 500, wrapLength: int = 240, shouldDisplay: Callable | None = None, background='#ffffff', font: Any = None)

Bases: object

create a tooltip for a given widget

__init__(widget: Widget, text: str | Callable[[], str] = '', canvasID: int | None = None, waitTime: int = 500, wrapLength: int = 240, shouldDisplay: Callable | None = None, background='#ffffff', font: Any = None)
Parameters:
  • widget – The widget at attach this tooltip to

  • text – Either a string to display or a no-argument function returning a str

  • canvasID – A required item ID if widget is a tk.Canvas, otherwise ignored.

  • waitTime – The time to wait in msec. [default=500]

  • wrapLength – The width to wrap at in pixels (0: no wrapping) – or a no-argument function giving it, asked each time it’s shown. [default=240]

  • shouldDisplay (Optional[Callable[[Self],bool]]) – A function taking this object as an argument returning a bool indicating that this text tool is to be displayed (asked when the pointer comes in). Either way, the tooltip isn’t displayed if its text is empty (asked once, when it’s about to be shown: so a function giving it isn’t called just for passing over).

  • font – The font for the text (eg: “TkFixedFont”, so text laid out with spaces stays aligned); by default, Tk’s default – or a no-argument function giving it (None for the default), asked each time it’s shown.

  • background (str)

Throws TypeError:

Throws ValueError:

delete()
enter(event=None)
Parameters:

event

leave(event=None)
Parameters:

event

schedule()
unschedule()
showtip(event=None)
Parameters:

event

WATCH_INTERVAL = 250

How often (msec) a tooltip that’s shown checks it’s still wanted (see watch()).

appActive() → bool
Returns:

Whether this program is the one in front (the user’s working in it): one of its windows has the keyboard focus.

pointerOver() → bool
Returns:

Whether the pointer’s over what this is the tooltip of: the widget – or, on a canvas, its item – within a few pixels.

stillWanted() → bool
Returns:

Whether a tooltip should be shown (or stay shown): this program’s in front, and the pointer’s over what it’s the tooltip of. (It’s -topmost: shown when the program isn’t in front – eg: a double-click opened another program, or the pointer left while it was busy – it’d float over the other programs’ windows; and a <Leave> can be missed: eg: when the item’s redrawn, moved or deleted under the pointer.)

watch() → None

While the tooltip’s shown: hide it as soon as it’s no longer wanted (see stillWanted()).

hidetip()