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. It is capable of fully integrating with custom tkinter
themes both light and dark ones.
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 tktooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
ToolTip(b, msg="Hover info")
app.mainloop()
Delayed tooltip
import tkinter as tk
import tkinter.ttk as ttk
from tktooltip 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 tktooltip 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. You can control the refresh rate of the ToolTip
through the refresh
argument by default it is set to 1s
.
import time
import tkinter as tk
import tkinter.ttk as ttk
from tktooltip import ToolTip
app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
# NOTE: pass the function itself not the return value
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 tktooltip 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()
Notes
- Certain options do not match great with each other, a good example is
follow
anddelay
using small x/y offsets. This can cause the tooltip to appear inside the widget. Hovering over the tooltip will cause it to disappear and reappear, in a new position, potentially again inside the widget.
Contributing
You can find the instructions on how to contribute in this project in the CONTRIBUTING.md file.
Acknowledgements
tkinter-tooltip
is based on the original work performed by
Tucker Beck
licensed under an MIT License.
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
File details
Details for the file tkinter_tooltip-3.1.1.tar.gz
.
File metadata
- Download URL: tkinter_tooltip-3.1.1.tar.gz
- Upload date:
- Size: 859.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ce57b8d79d02bcdbca93747149f74b73efce75415f9277c96d0e215549133d |
|
MD5 | 68e89471a2eaebbb98b41f71d83c7bf1 |
|
BLAKE2b-256 | 2e23d0cd4786ce8c195603e238d172ace436641561de48782865783331c14296 |
File details
Details for the file tkinter_tooltip-3.1.1-py3-none-any.whl
.
File metadata
- Download URL: tkinter_tooltip-3.1.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb8d745b83a2bbceff16692e4b447e055df805aeadd0bb98e0410ce8cf36ef4 |
|
MD5 | 5e5958176296a5fc47130f22c06906e1 |
|
BLAKE2b-256 | 13a5b47bc730966e705e779f5221cc00fee8b00fd949d34c850b4f4d4366ef6c |