Home Ask Login Register

Developers Planet

Your answer is one click away!

aless80 February 2016

Tkinter button changes color after having hovered on it

I create a button that I want to be white/red when disabled/active:

self.btn = tk.Button(cfg.win, text="Button", name = "btn", state="disabled", bg="white", activebackground="red")

where self refers to my Gui class, cfg.win is a Tkinter window with the .Tk() method.

Then a callback changes the color of the button:

self.btn.configure(state = "active")

The button turns red. When I hover on the mouse with the mouse the color is still red. However, when I leave the area of the button it turns white. The button stays active. What am I missing?


aless80 February 2016

I see that a button state can be normal, active or disabled. The documentation does not say much tkinter buttons but it appears that the button is active when I hover on it with the mouse, and normal when my mouse is not on its area. So the following did the trick

self.btn.configure(state = "normal", relief="raised", bg = "red")

Post Status

Asked in February 2016
Viewed 1,460 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life