An easy and customisable ToolTip implementation for Tkinter
Project description
tkinter-tooltip
What this is
This is a simple yet fully customisable tooltip/pop-up implementation for
tkinter
widgets based on the original work performed by
Tucker Beck
Features
- normal tooltips
- show tooltip with
s
secondsdelay
- tooltip tracks mouse cursor
- tooltip displays strings and string returning functions
- fully customisable, tooltip inherits underlying theme style
Install
pip install tkinter-tooltip
Examples
Normal tooltips
By default the tooltip activates when entering and/or moving in the widget are and deactivates when leaving and/or pressing any button.
import tkinter as tk
import tkinter.ttk as ttk
from tooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button").pack()
ToolTip(b, msg="Hover info")
app.mainloop()
Delayed tooltip
import tkinter as tk
import tkinter.ttk as ttk
from tooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
ToolTip(b, msg="Hover info", delay=2.0) # True by default
app.mainloop()
Tracking tooltip
Have the tooltip follow the mousse cursor around when moving.
import tkinter as tk
import tkinter.ttk as ttk
from tooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
ToolTip(b, msg="Hover info", follow=True) # True by default
app.mainloop()
Function as tooltip
Here the tooltip returns the value of time.asctime()
which updates with every
movement. NOTE: the values do not update when the cursor is stationary.
import time
import tkinter as tk
import tkinter.ttk as ttk
from tooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
ToolTip(b, msg=time.asctime(), delay=0)
app.mainloop()
Themed tooltip
tkinter-tooltip
is fully aware of the underlying theme (in this case a dark theme),
and can even be furher customised by passing tk
styling arguments to the tooltip
Style tooltip and underlying the button. If a full theme has been used then
the ToolTip
will inherit the settings of the theme by default.
import tkinter as tk
import tkinter.ttk as ttk
from tooltip import ToolTip
app = tk.Tk()
s = ttk.Style()
s.configure("custom.TButton", foreground="#ffffff", background="#1c1c1c")
b = ttk.Button(app, text="Button", style="custom.TButton")
b.pack()
ToolTip(b, msg="Hover info", delay=0,
parent_kwargs={"bg": "black", "padx": 5, "pady": 5},
fg="#ffffff", bg="#1c1c1c", padx=10, pady=10)
app.mainloop()
Acknowledgements
Special thanks to Tucker Beck for writting the original version of the code.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for tkinter_tooltip-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d051f05d5943a17ed554674c06289984445c9f0bb99b464957867f1b7d42c48b |
|
MD5 | 0cf417d11e49213e00677ed4a8ed401a |
|
BLAKE2b-256 | 39778d47d07668d118e620996221d4a53b9f2b00a9aa4b8fdfcfae49e1ab1d7c |