Python Kivy Gif动画运行太频繁
我想用gif动画制作一个kivy程序,它运行一次,然后停止。 我将anim_loop设置为1,但它会一次又一次地运行。 代码如下:Python Kivy Gif动画运行太频繁,python,kivy,gif,animated-gif,Python,Kivy,Gif,Animated Gif,我想用gif动画制作一个kivy程序,它运行一次,然后停止。 我将anim_loop设置为1,但它会一次又一次地运行。 代码如下: Root = Builder.load_string(''' Image: source: 'streifen1.gif' size_hint_y: 1 anim_loop: 1 ''') class TTT(App): def build(self): Window.clearcolor = (0, 0.5, 1, 1)#
Root = Builder.load_string('''
Image:
source: 'streifen1.gif'
size_hint_y: 1
anim_loop: 1
''')
class TTT(App):
def build(self):
Window.clearcolor = (0, 0.5, 1, 1)# sets the backgroundcolor
return Root #returnst the kv string and therefore the root widget`
<代码> MynLoCult属性应在Kyy1.1.0中工作,如果使用旧版本,则考虑升级。 还有另一种方法。可以使用以下代码停止动画:
myimage._coreimage.anim_reset(False)
要在播放动画一次后停止动画,请观察纹理
属性。它将在加载每个框架后更改。如果GIF有n帧,则在调用on_texture
方法(n+1)次后停止动画
from kivy.app import App
from kivy.uix.image import Image
class MyImage(Image):
frame_counter = 0
frame_number = 2 # my example GIF had 2 frames
def on_texture(self, instance, value):
if self.frame_counter == self.frame_number + 1:
self._coreimage.anim_reset(False)
self.frame_counter += 1
class MyApp(App):
def build(self):
return MyImage(source = "test.gif")
if __name__ == '__main__':
MyApp().run()
你用的是kivy 1.9吗?您是否可以尝试压缩图像而不是gif,这可能会得到更好的支持?@Sarment我该怎么做,文档中没有任何内容:制作一个包含图像的压缩文件,并将图像源指向该文件名。@Sarment,希望它像您描述的那样简单,但我已经尝试过了,没有乐趣。我们已经到了无证区,开始接触巫术了。基维,救命!!非常感谢你,你无法想象你帮了多少忙me@Gilgamesch,我想如果您对这一评论作出回答,我可以更快地帮助您: