Python / Kivy / Gif:如何在动画后删除 gif
我想要一个 Gif 作为开场动画,在动画结束后将其删除或移走。然而似乎没有任何作用,图像只是停留在那里。
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.textinput import TextInput
from kivy.core.text import LabelBase
from kivy.uix.image import Image
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.app import App
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.extras.highlight import KivyLexer
from kivy.lang.parser import ParserException
from kivy.properties import ColorProperty
from kivymd.uix.label import MDLabel
from kivy.animation import Animation
from kivy.uix.screenmanager import ScreenManager, Screen
import time
import threading
import random
kv = ("""
FloatLayout:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'test_back.png'
Image:
id: intro
source: 'test_anim.gif'
size_hint: None, None
size: "500dp", "500dp"
pos_hint: {'center_x':.5, 'center_y':.5}
allow_stretch: False
anim_delay: 0.05
anim_loop: 1
""")
class testApp(App):
def build(self):
kivy_design = Builder.load_string(kv)
self.app_root = kivy_design
return kivy_design
def on_start(self):
frame_counter = 0
frame_counter += 1
if frame_counter == 30:
self.app_root.ids.intro.pos_hint = {'center_x':-.5, 'center_y':-.5}
testApp().run()
我现在尝试了相当长一段时间,也研究了其他类似的问题。
我缺少什么?感谢您的阅读
I want to have a Gif as an opening animation that is deleted or moved away after the animation. However nothing seems to work, the image just stays there.
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.textinput import TextInput
from kivy.core.text import LabelBase
from kivy.uix.image import Image
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.app import App
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.extras.highlight import KivyLexer
from kivy.lang.parser import ParserException
from kivy.properties import ColorProperty
from kivymd.uix.label import MDLabel
from kivy.animation import Animation
from kivy.uix.screenmanager import ScreenManager, Screen
import time
import threading
import random
kv = ("""
FloatLayout:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'test_back.png'
Image:
id: intro
source: 'test_anim.gif'
size_hint: None, None
size: "500dp", "500dp"
pos_hint: {'center_x':.5, 'center_y':.5}
allow_stretch: False
anim_delay: 0.05
anim_loop: 1
""")
class testApp(App):
def build(self):
kivy_design = Builder.load_string(kv)
self.app_root = kivy_design
return kivy_design
def on_start(self):
frame_counter = 0
frame_counter += 1
if frame_counter == 30:
self.app_root.ids.intro.pos_hint = {'center_x':-.5, 'center_y':-.5}
testApp().run()
I tried now for quite some time and also looked at other similar issues like this.
What am I missing? Thanks for reading
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以安排删除
intro
,并继续延迟删除,直到gif
停止。这是执行此操作的代码的修改版本:You can schedule the removal of the
intro
, and keep delaying that removal until thegif
stops. Here is a modified version of your code that does that:我不确定编码的答案是什么,但理论上可能是你找到了 GIF 的长度。在一个页面上播放 GIF,并设置 GIF 长度的显示时间,然后再显示另一个页面,显示您想要的内容。
I am not sure what the coded answer will be, but the theory could be that you find the length of the GIF. Play the GIF on a page and set the time for display for the length of the GIF then just display another page with what you want afterwards.