1
我从这里得到了一个有用的用户代码,它几乎是完美的。如何将两个不同的gif绑定到kivy中的切换按钮?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
Builder.load_string("""
<ExampleApp>:
id: main
orientation: "vertical"
Button:
size_hint_x: None
size_hint_y: None
height: 300
width: self.height
center: self.parent.center
text: ""
on_press: gif.anim_delay = 0.09
on_press: gif._coreimage.anim_reset(True)
Image:
id: gif
source: 'power_on.gif'
center: self.parent.center
height: 300
width: self.height
allow_stretch: True
anim_delay: -1
anim_loop: 1
""")
class ExampleApp(App, BoxLayout):
def build(self):
return self
if __name__ == "__main__":
ExampleApp().run()
我需要它使用两个不同的GIF的GIF POWER_ON时,它的切换上,当它切换关闭POWER_OFF GIF。所以我试图将其更改为切换按钮,并添加了
on_press: gif.source="power_off.gif"
但这并没有奏效。它甚至从未玩过power_on gif,因为它立即将gif的源码更改为power_off
这样做的正确方法是什么?