Skip to content

ToolTip

__init__

__init__(
    widget: Misc,
    text: str = "widget info",
    padding: int = 10,
    justify: Literal["left", "center", "right"] = "left",
    accent: Optional[str] = None,
    wraplength: Optional[int] = None,
    delay: int = 250,
    image: Any = None,
    anchor_point: Optional[AnchorPoint] = None,
    window_point: Optional[AnchorPoint] = None,
    auto_flip: Union[
        bool, Literal["vertical", "horizontal"]
    ] = True,
    **kwargs: Any,
) -> None

Initialize a ToolTip instance for the specified widget.

Creates a tooltip that appears after a configurable delay when the mouse enters the widget and disappears when the mouse leaves or on button press. The tooltip can either follow the mouse pointer or be anchored to a specific position relative to the widget.

The tooltip window is created with semi-transparency (alpha=0.95 by default) and uses the Bootstrap styling system for consistent theming. Text automatically wraps based on the specified wraplength, and optional images can be displayed alongside the text.

Parameters:

Name Type Description Default
widget Misc

The tkinter widget to attach this tooltip to. The tooltip will appear when hovering over this widget.

required
text str

The text content to display in the tooltip. Supports multi-line text that will wrap according to wraplength. Defaults to "widget info".

'widget info'
padding int

The internal padding in pixels between the tooltip text and the tooltip border. Defaults to 10.

10
justify Literal['left', 'center', 'right']

Text alignment within the tooltip. Valid options are "left", "center", or "right". Defaults to "left".

'left'
accent Optional[str]

Accent token for the tooltip frame (e.g., "danger", "info"). If None, uses default elevated background styling.

None
bootstyle

DEPRECATED - Use accent instead. Bootstrap style(s) to apply to the tooltip frame.

required
wraplength Optional[int]

Maximum width in screen units before text wraps to a new line. If None, defaults to a scaled value of 300 based on the widget's display.

None
delay int

Time in milliseconds to wait before showing the tooltip after mouse enters the widget. Defaults to 250ms.

250
image Any

Optional image to display in the tooltip below the text. Should be a PhotoImage or compatible tkinter image object.

None
anchor_point Optional[AnchorPoint]

Point on the widget to anchor to (n, s, e, w, ne, nw, se, sw, center). If None, tooltip follows the mouse pointer.

None
window_point Optional[AnchorPoint]

Point on the tooltip window to align with anchor_point (n, s, e, w, ne, nw, se, sw, center). If None, auto-defaults to the opposite of anchor_point for natural positioning.

None
auto_flip Union[bool, Literal['vertical', 'horizontal']]

Smart positioning to keep tooltip on screen. Defaults to True. - False: No flipping - True: Flip both vertically and horizontally as needed - 'vertical': Only flip up/down - 'horizontal': Only flip left/right

True
**kwargs Any

Additional keyword arguments passed to the Toplevel window constructor. Common options include alpha, topmost, etc. The arguments overrideredirect, master, and windowtype are set automatically.

{}

destroy

destroy() -> None

Cleanup tooltip resources and unbind all event handlers.

This method should be called when the tooltip is no longer needed to prevent memory leaks. It cancels any pending tooltip display, hides any visible tooltip, and removes all event bindings from the widget.