【问题标题】:I want to make a second animation after the first with kivy abd MDLabel我想在第一个动画之后用 kivy abd MDLabel 制作第二个动画
【发布时间】:2020-08-16 15:38:38
【问题描述】:

所以我创建了 2 个标签并为第一个设置了动画,但我无法使第二个动画工作我想在具有相同动画属性的标签之后为标签 2 设置动画

Class DemoApp(MDApp):  
    def build(self,*args):
             labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom', text_color = (0,0,0,1),font_style ='H4')
             labels2 = MDLabel(text='Welcome to Eden', halign='center', theme_text_color='Custom',text_color=(0, 0, 0, 1), 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

【问题讨论】:

    标签: python animation kivy


    【解决方案1】:

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

    Class DemoApp(MDApp):  
        def build(self,*args):
                 labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom', text_color = (0,0,0,1),font_style ='H4')
                 labels2 = MDLabel(text='Welcome to Eden', halign='center', theme_text_color='Custom',text_color=(0, 0, 0, 1), 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
    

    【讨论】:

    • 感谢您的回答!不幸的是,它只播放第一个动画,也许最后是返回导致了问题?
    • 可能是。你能解释一下你想用两个标签做什么吗?只是改变文本属性吗?在这种情况下,您不需要定义第二个标签。相反,您可以通过 labels.text = 'Welcome Eden' 之类的语句在 on_complete 方法中执行此操作。
    • 它只使用一个标签,我将 labels.text = 'welcome Eden' 放在 _cmp 的第一行,谢谢你的帮助!
    猜你喜欢
    • 2014-11-16
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多