我想用kivy abd MDLabel制作第一个动画之后的第二个动画

问题描述

所以我创建了2个标签,并对第一个标签进行了动画处理,但是我无法使第二个动画工作,因此我想在具有相同动画属性标签后立即对label2进行动画处理

Class DemoApp(MDApp):  
    def build(self,*args):
             labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom',text_color = (0,1),font_style ='H4')
             labels2 = MDLabel(text='Welcome to Eden',halign='center',theme_text_color='Custom',text_color=(0,font_style='H4')


             anim = Animation(opacity=0,duration=0)
             anim += Animation(opacity=1,duration=4)
             anim += Animation(opacity=0,duration=2)
             anim.start(labels)
             return labels

解决方法

您可以绑定第一个标签的on_complete动画方法来开始第二个标签的动画,如下所示:

Class DemoApp(MDApp):  
    def build(self,*args):
             labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom',text_color = (0,1),font_style ='H4')
             labels2 = MDLabel(text='Welcome to Eden',halign='center',theme_text_color='Custom',text_color=(0,font_style='H4')


             anim = Animation(opacity=0,duration=0)
             anim += Animation(opacity=1,duration=4)
             anim += Animation(opacity=0,duration=2)
             def _cmp(*args):
                 anim2 = Animation(opacity=0,duration=0)
                 anim2 += Animation(opacity=1,duration=4)
                 anim2 += Animation(opacity=0,duration=2)
                 anim2.start(labels2)
             anim.bind(on_complete=_cmp)
             anim.start(labels)
             return labels

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...