I have this toggle button in kivy and I want it to animate on when pressed (it's a power on button gif) but without looping. I can't seem to find any useful information about this. Any help is appreciated, thanks!
I don't think a GIF can have a clickable link (like a specific button or text to click on), but the GIF itself can be clickable. That would be set in HTML when putting the GIF on a website/email, the same as making a button or other image (PNG, JPG, etc.) clickable.
To play animated GIF files, you must open the files in the Preview/Properties window. To do this, select the animated GIF file, and then on the View menu, click Preview/Properties. If the GIF does not play, try re-saving the animated GIF in the collection in which you want to put it.
You can use a free extension called Google GIFs Chrome Extension or Google gifs autoplay to do that. This extension works silently in the background and plays all animated GIFs in the Google image search results.
Using an instance of kivy.uix.image
inside the button you can do:
Disable animation at startup anim_delay = -1
.
Specify the number of loops to be played using anim_loop = 1
When the button is pressed, assign a positive value to anim_delay
and restart animation using the anim_reset
method of the kivy.core.image
instance used by kivy.uix.image
to contain the image.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
Builder.load_string("""
<ExampleApp>:
orientation: "vertical"
Button:
text: ""
on_press: gif.anim_delay = 0.10
on_press: gif._coreimage.anim_reset(True)
Image:
id: gif
source: 'img.gif'
center: self.parent.center
size: 500, 500
allow_stretch: True
anim_delay: -1
anim_loop: 1
""")
class ExampleApp(App, BoxLayout):
def build(self):
return self
if __name__ == "__main__":
ExampleApp().run()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With