Skip to content

feat: add ability to show and hide the tooltip #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tktooltip/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(
self.refresh = refresh
self.x_offset = x_offset
self.y_offset = y_offset
self._hidden = False
# visibility status of the ToolTip inside|outside|visible
self.status = ToolTipStatus.OUTSIDE
self.last_moved = 0
Expand Down Expand Up @@ -130,6 +131,23 @@ def destroy(self) -> None:
self.bindigs.clear()
super().destroy()

def hide(self) -> None:
"""Hides (aka. disables) the ToolTip."""
self._hidden = True
self.withdraw()

def show(self) -> None:
"""Enables the ToolTip after previously hiding (disabling) it.

This does not immediately show the tooltip, but
rather allows the tooltip to be shown when appropriate (i.e. on
next enter). If appropriate, the tooltip is shown immediately
"""
self._hidden = False
if self.state == ToolTipStatus.VISIBLE:
self._update_message()
self.deiconify()

def on_enter(self, event: tk.Event) -> None:
"""
Processes motion within the widget including entering and moving.
Expand Down Expand Up @@ -183,7 +201,8 @@ def _show(self) -> None:

if self.status == ToolTipStatus.VISIBLE:
self._update_message()
self.deiconify()
if not self._hidden:
self.deiconify()

# Recursively call _show to update ToolTip with the newest value of msg
# This is a race condition which only exits when upon a binding change
Expand Down
Loading