I want the information to be entered when I press a button with a red background. / But it doesn\'t work. / How can I make it enter when the button background is red?
<if b0 == 'red':
compares the button b0
to the string 'red'
. If you think about it, it's clear that a button will never equal a string.
You probably want to get the current background color of the button. Since bg
is a config option, you can use the cget method to read its current value:
if b0.cget('bg') == 'red':
By the way, if you'd want to change the bg
config value on an already existing widget, you could use the config method: b0.config(bg='red')
. For more info about configuration in Tkinter, see this page.
Note that for convenience, Tkinter widgets also implement a partial dictionary interface, so you can also use b0['bg']
to read or write the value.