Tkinter ttkbootstrap ToolTip Tutorial

The ttkbootstrap ToolTip class displays a styled popup help window when the mouse hovers over a widget and closes automatically when the pointer leaves the widget or clicks it.

Tutorial Breakdown:

Part I: Basic ToolTip Hover Popups & Parameters

Ttkbootstrap Tooltip Import ToolTip from ttkbootstrap.widgets and attach it to any target ttkbootstrap Button or widget using the Grid layout manager.

Parameter Description
text Message or help text displayed inside the popup window.
bootstyle Style keyword such as PRIMARY, SECONDARY, SUCCESS, INFO, WARNING, DANGER, LIGHT, DARK, or tuple combinations like (INFO, INVERSE).
wraplength Maximum width of the popup window before text wraps onto the next line.
**kwargs Additional keyword arguments passed to the underlying tooltip configuration.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.widgets import ToolTip

my_w = ttk.Window()
my_w.geometry("500x200")

b1 = ttk.Button(my_w, text="Start", bootstyle=SUCCESS)
b1.grid(row=2, column=1, padx=40, pady=40)

b2 = ttk.Button(my_w, text="Stop", bootstyle=DANGER)
b2.grid(row=2, column=2, padx=40, pady=40)

b3 = ttk.Button(my_w, text="Jump", bootstyle=PRIMARY)
b3.grid(row=2, column=3, padx=40, pady=40)

b4 = ttk.Button(my_w, text="Reset", bootstyle=WARNING)
b4.grid(row=2, column=4, padx=40, pady=40)

tt1 = ToolTip(b1, text="This is to Start", bootstyle=(INFO, INVERSE))
tt2 = ToolTip(b2, text="This is Stop the Project", bootstyle=DANGER)
tt3 = ToolTip(b3, text="This is Jump the Project", bootstyle=(SUCCESS, INVERSE))
tt4 = ToolTip(
    b4, text="This is Reset the Project", wraplength=100, bootstyle=(SECONDARY, INVERSE)
)

my_w.mainloop()
ToolTip of Ttkbootstrap to show Help text when mouse is over the widget #14

Part II: Controlling Visibility with show_tip() & hide_tip()

Ttkbootstrap Tooltip hide_tip() show_tip() In this example, the tooltip (tt1) on the Start button is shown when the Floodgauge value is below 25 using tt1.show_tip(), and hidden once progress moves into higher ranges using tt1.hide_tip().

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.widgets import ToolTip

my_w = ttk.Window()
my_w.geometry("520x320")

fg = ttk.Floodgauge(
    bootstyle=INFO,
    mask="Progress {}%",
    value=10,
    length=500,
)
fg.grid(row=1, column=1, padx=10, pady=50, columnspan=4)

b1 = ttk.Button(my_w, text="Start", command=lambda: fg.start(), bootstyle=SUCCESS)
b1.grid(row=2, column=1, padx=10, pady=40)

b2 = ttk.Button(my_w, text="Stop", command=lambda: fg.stop(), bootstyle=DANGER)
b2.grid(row=2, column=2, padx=10, pady=40)

b3 = ttk.Button(my_w, text="Jump", command=lambda: fg.step(5), bootstyle=PRIMARY)
b3.grid(row=2, column=3, padx=10, pady=40)

b4 = ttk.Button(
    my_w, text="Reset", command=lambda: fg.configure(value=10), bootstyle=WARNING
)
b4.grid(row=2, column=4, padx=10, pady=40)


def my_upd(*args):
    if fg.variable.get() < 25:
        fg.configure(bootstyle=INFO)
        tt1.show_tip()
    elif fg.variable.get() < 50:
        fg.configure(bootstyle=SUCCESS)
        tt1.hide_tip()
    elif fg.variable.get() < 80:
        fg.configure(bootstyle=WARNING)
    else:
        fg.configure(bootstyle=DANGER)


fg.variable.trace("w", my_upd)
tt1 = ToolTip(b1, text="This is Started", bootstyle=(INFO, INVERSE))
tt2 = ToolTip(b2, text="This will Stop the Project", bootstyle=DANGER)
tt3 = ToolTip(b3, text="This is to Jump the Project", bootstyle=(SUCCESS, INVERSE))
tt4 = ToolTip(
    b4, text="This is Reset the Project", wraplength=100, bootstyle=(SECONDARY, INVERSE)
)
my_w.mainloop()

Part III: Live Dynamic Theme Switcher with ToolTip

Ttkbootstrap Tooltip hide_tip() show_tip()

Using StringVar and Radiobutton widgets, you can switch themes at runtime with app.style.theme_use() and verify how ToolTip popups render across light and dark themes.

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.widgets import ToolTip

app = ttk.Window(title="ToolTip Theme Switcher", themename="bootstrap-light")
app.geometry("480x210")

theme_var = ttk.StringVar(value="bootstrap-light")
themes = ["bootstrap-light", "bootstrap-dark", "nord-light", "nord-dark"]


def change_theme():
    selected = theme_var.get()
    app.style.theme_use(selected)
    lbl_status.config(text=f"Active Theme: {selected}")


ttk.Label(
    app, text="Select Theme:", font=("Helvetica", 11, "bold")
).grid(row=0, column=0, columnspan=4, padx=15, pady=12, sticky="w")

for idx, t_name in enumerate(themes):
    ttk.Radiobutton(
        app,
        text=t_name,
        value=t_name,
        variable=theme_var,
        command=change_theme,
        bootstyle="outline-toolbutton"
    ).grid(row=1, column=idx, padx=5, pady=5)

btn_save = ttk.Button(app, text="Save Settings", bootstyle=SUCCESS)
btn_save.grid(row=2, column=0, columnspan=2, padx=15, pady=20)
ToolTip(btn_save, text="Persist current preferences to disk", bootstyle=(INFO, INVERSE))

lbl_status = ttk.Label(app, text="Active Theme: bootstrap-light", bootstyle=INFO)
lbl_status.grid(row=2, column=2, columnspan=2, padx=15, pady=20, sticky="w")

app.mainloop()

Part IV: SQLite Database Integration (Dynamic Field Hints)

In data-entry forms or configurable desktop utilities, storing tooltip guidance in an SQLite database via SQLAlchemy lets you update field hints centrally without changing GUI code.

1️⃣ Creating SQLite Table & Sample Tooltip Hints

from sqlalchemy import create_engine, text

DATABASE_URL = "sqlite:///tooltip_hints.db"
engine = create_engine(DATABASE_URL, echo=False)

with engine.connect() as conn:
    conn.execute(text("""
        CREATE TABLE IF NOT EXISTS field_hints (
            field_key TEXT PRIMARY KEY,
            hint_text TEXT NOT NULL
        )
    """))

    count = conn.execute(text("SELECT COUNT(*) FROM field_hints")).scalar()
    if count == 0:
        conn.execute(text("""
            INSERT INTO field_hints (field_key, hint_text) VALUES
            ('student_name', 'Enter full student name as printed on ID card'),
            ('student_grade', 'Enter grade code such as A, B, or C')
        """))
        conn.commit()

print("Tooltip hints table ready.")

2️⃣ Loading ToolTip Text from SQLite

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.widgets import ToolTip
from sqlalchemy import create_engine, text

DATABASE_URL = "sqlite:///tooltip_hints.db"
engine = create_engine(DATABASE_URL, echo=False)


def get_hint(field_key, fallback):
    with engine.connect() as conn:
        row = conn.execute(
            text("SELECT hint_text FROM field_hints WHERE field_key = :k"),
            {"k": field_key}
        ).fetchone()
    return row[0] if row else fallback


app = ttk.Window(title="Database ToolTip Hints", themename="bootstrap-light")
app.geometry("440x180")

ttk.Label(app, text="Student Name:").grid(row=0, column=0, padx=15, pady=15, sticky="w")
ent_name = ttk.Entry(app, width=28)
ent_name.grid(row=0, column=1, padx=10, pady=15)
ToolTip(ent_name, text=get_hint("student_name", "Enter student name"), wraplength=220)

ttk.Label(app, text="Grade:").grid(row=1, column=0, padx=15, pady=15, sticky="w")
ent_grade = ttk.Entry(app, width=28)
ent_grade.grid(row=1, column=1, padx=10, pady=15)
ToolTip(ent_grade, text=get_hint("student_grade", "Enter grade"), wraplength=220)

app.mainloop()

Part V: Connecting to MySQL using SQLAlchemy

To read shared tooltip hints from a centralized MySQL database server, update DATABASE_URL to use PyMySQL while keeping the same SQLAlchemy query pattern:

# SQLite Connection (Commented Out)
# DATABASE_URL = "sqlite:///tooltip_hints.db"

# MySQL Connection string using PyMySQL
DATABASE_URL = "mysql+pymysql://username:password@localhost/student_db"

engine = create_engine(DATABASE_URL, echo=False)

Common Errors & Troubleshooting

Issue / Error Cause Recommended Solution
ModuleNotFoundError: No module named 'ttkbootstrap.tooltip' Using the legacy ttkbootstrap.tooltip submodule path removed in ttkbootstrap 2.x. Import from ttkbootstrap.widgets: from ttkbootstrap.widgets import ToolTip.
Long tooltip text stretches too wide across screen No wraplength value was provided for a longer help string. Pass wraplength=180 (or another suitable width) to wrap text cleanly.
Programmatic show_tip() / hide_tip() behaves unexpectedly Called before widgets are laid out or on a hidden/unmapped widget. Trigger show_tip() and hide_tip() inside event callbacks or variable traces after creating the widget and ToolTip instance.

Frequently Asked Questions

A ToolTip closes when the mouse pointer leaves the target widget or when the user clicks the widget.

Yes. You can pass any Tkinter or ttkbootstrap widget—such as Entry, Label, Combobox, Checkbutton, or Floodgauge—as the first argument to ToolTip(widget, text=...).

Assign the ToolTip(...) instance to a variable (such as tt1) and call tt1.show_tip() or tt1.hide_tip() when application state changes.



Subscribe to our YouTube Channel here



plus2net.com




Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer