2015-06-27 113 views
1

我想用一个运行一次然后停止的gif动画制作一个kivy程序。 我将anim_loop设置为1,但它一直运行一遍又一遍。 下面是代码:Kivy Gif动画运行频率过高

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` 
+0

您使用的是kivy 1.9吗?你是否可以尝试一下你的图片而不是一个gif,这可能会更好地支持? – inclement

+0

@inclement我该如何做到这一点,在文档中没有任何关于它的内容:http://kivy.org/docs/api-kivy.uix.image.html?highlight=image#kivy.uix.image – Gilgamesch

+0

制作一个包含你的图像的zip文件,并将图像源指向该文件名。 – inclement

回答

2

anim_loop属性应该在Kivy 1.9.0工作,如果你使用的是旧版本,然后再考虑升级。

还有一种方法。您可以使用下面的代码停止动画:

myimage._coreimage.anim_reset(False) 

要停止的动画有人打一次后观察texture属性格式。它将在加载每个帧后进行更改。如果您的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() 
+0

非常感谢,你不能imagen你有多少帮助我 – Gilgamesch

+0

@Gilgamesch,我想我可以帮助你越早,如果你有回答这个评论:http://stackoverflow.com/questions/30726524/run-an- GIF动画,一次-ON-kivy仅#comment49537709_30727495 – Nykakin