I want the information to be entered when I press a button with a red background

前端 未结 1 971
青春惊慌失措
青春惊慌失措 2021-01-24 05:41

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?

<
相关标签:
1条回答
  • 2021-01-24 06:12

    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.

    0 讨论(0)
提交回复
热议问题