mr. bug
mr. bug

Reputation: 309

How to change the color of a tooltip using the Pmw module in python?

I am trying to make a tooltip in Tkinter by using the Pmw module. When the user hovers the mouse over the button I want to display a tooltip with a black background and white text but I can't figure out how to do that.

Here is the code I am using:

from tkinter import *
import Pmw

root = Tk()
Pmw.initialise(root)

# Create some random widget
button = Button(root, text=" This is a Test", pady=30)
button.pack(pady=10)

# create balloon object and bind it to the widget
balloon = Pmw.Balloon(root)
balloon.bind(button, "Text for the tool tip")

mainloop()

How would I go about changing the text color and background color of the tooltip?

Upvotes: 1

Views: 556

Answers (1)

Art
Art

Reputation: 3089

Get the label component of the tooltip using balloon.component("label") then use config on that label.

Here is an example:

from tkinter import *
import Pmw

root = Tk()
Pmw.initialise(root)

# Create some random widget
button = Button(root, text=" This is a Test", pady=30)
button.pack(pady=10)

# create balloon object and bind it to the widget
balloon = Pmw.Balloon(root)
balloon.bind(button, "Text for the tool tip")

lbl = balloon.component("label")
lbl.config(background="black", foreground="white")
# Pmw.Color.changecolor(lbl, background="black", foreground="white")

root.mainloop()

Upvotes: 2

Related Questions