在kivy中单击时如何更改按钮的背景图像?

How to change background image of button when clicked in kivy?

我有两张图片作为按钮的背景,其中一张是按钮的默认图片,我想在点击按钮时更改按钮的背景图片。 这是我的代码:

class Control_(Screen):
    Status = 0
    print(Status)
    def StatusButton(self):
        if self.Status == 0:
            self.Status = 1
            print(self.Status)
        elif self.Status == 1:
            self.Status = 0   
            print(self.Status) 

*.kv 是:

<Control_>:
    Button:
        background_normal: "on.png"
        size_hint: .3, .2
        pos_hint: {"x":.3, "y":.3} 
        on_release:root.StatusButton()
            

这是我的图片:

try that



 <Control_>:
        Button:
            background_normal: "on.png"
            size_hint: .3, .2
            pos_hint: {"x":.3, "y":.3} 
            on_release:self.background_normal="on.png" if background_normal=="off.png" else "off.png"