Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter button changes color after having hovered on it

Tags:

python

tkinter

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?

like image 445
aless80 Avatar asked Feb 09 '16 01:02

aless80


1 Answers

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")
like image 112
aless80 Avatar answered Sep 29 '22 08:09

aless80