CTkToolTip

repository·main·Indexed 41 days ago

https://github.com/akascape/ctktooltip

A lightweight Python utility for adding customizable pop-up tooltips to customtkinter widgets. It supports dynamic message updates via .configure(), custom styling for colors and fonts, and control methods such as .hide(), .show(), and .get().

Tokens
925
Snippets
3
Records
5
Agent score
50%

What's inside CTkToolTip

  1. Use CTkToolTip for simple tooltips

    main

    To create a basic tooltip, instantiate the CTkToolTip class by passing the target customtkinter widget and a message string. The tooltip will appear when the user hovers over the widget.

    CTkToolTip(widget, message="Your Message")
  2. Implement dynamic tooltips in a CTk application

    main

    You can create interactive tooltips that update dynamically. For example, you can link a CTkSlider to a tooltip to display its current value by calling .configure(message=...) on the tooltip instance within the slider's command callback.

    import customtkinter
    from CTkToolTip import *
    
    def show_value(value):
        tooltip_1.configure(message=int(value))
        
    def show_text():
        print(tooltip_2.get())
    
    root = customtkinter.CTk()
    
    slider = customtkinter.CTkSlider(root, from_=0, to=100, command=show_value)
    slider.pack(fill="both", padx=20, pady=20)
    
    tooltip_1 = CTkToolTip(slider, message="50")
    
    button = customtkinter.CTkButton(root, command=show_text)
    button.pack(fill="both", padx=20, pady=20)
    
    tooltip_2 = CTkToolTip(button, delay=0.5, message="This is a CTkButton!")
    
    root.mainloop()
  3. Use CTkToolTip methods

    main

    The CTkToolTip instance provides several methods to control its state and content:

    • .configure(message, arguments...): Update the tooltip text or other parameters dynamically.
    • .get(): Retrieve the current text of the tooltip.
    • .hide(): Disable the tooltip from appearing.
    • .show(): Re-enable the tooltip.
    • .is_disabled(): Check if the tooltip is currently disabled.
  4. Configure CTkToolTip arguments

    main

    The CTkToolTip constructor accepts several arguments to customize appearance and behavior:

    ParameterDescription
    widgetbind the tooltip to the ctk widget
    messageshow the message over the toolip
    delayadd a small delay before showing the tooltip (default is 0.2)
    followfollow the mouse cursor while hovering (default is True)
    x_offsetchange the horizontal offset of the tooltip widget from mouse cursor
    y_offsetchange the vertical offset of the tooltip widget from mouse cursor
    alphachange the transparency effect of the tooltip (range: 0-1)
    bg_colorchange the background color of the tooltip
    corner_radiusroundness of the corners
    border_widthadd a border around the tooltips (default is 0)
    border_colorchange the color of the border width
    paddingadd padx and pady inside the tooltip frame, tuple: (padx, pady)
    text_colorchange the text color of tooltip
    wraplengthconstrains the width of the tooltip, causing CTkToolTip, where required, to wrap the message at word boundaries.
    fontlabel text font, tuple: (font_name, size)
    justifychange the text display structure (left, right or center)
    always_on_topif True, the tooltip will stay above all other windows (default is False)
    Other Label ParametersAll other parameters for ctk label can be passed in ctktooltip