Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset background color of a python tkinter button?

Tags:

python

tkinter

Simple question, have parsed numerous search results, haven't found a simple answer. I set a very urgent button to red if something is not found so users click it first. Once clicked, I want to set the background back to normal like button.config(bg=''). I tried 'grey' but it's not the right color.

What do I set it to?

like image 755
user3000724 Avatar asked Mar 18 '16 20:03

user3000724


2 Answers

You can ask the button what color it is before you change it. Save the color, and then restore it later:

orig_color = the_button.cget("background")
the_button.configure(background="red")
...
the_button.configure(background=orig_color)
like image 127
Bryan Oakley Avatar answered Sep 20 '22 01:09

Bryan Oakley


I use the code:

def ToGray(self, to_gray):
    to_gray['bg'], to_gray['fg'] = "SystemButtonFace", "Black"

Then you can get the default button or label.

like image 32
Latifah Avatar answered Sep 20 '22 01:09

Latifah