Kivy标签文本淡入

2024-09-28 21:58:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用kivy中的动画工具使标签中的一些文字淡入淡出,但我不能让它工作,我在互联网上找不到任何帮助。 代码如下:

.py:

class TestScreen(Screen):
    def animate (self):
        anim = Animate(opacity=1, duration=2)
        anim.start(self.lbl)

千伏

^{pr2}$

Tags: 工具代码pyselfdef动画互联网标签
1条回答
网友
1楼 · 发布于 2024-09-28 21:58:40
  • Animation更改{}
  • opacity=1表示标签可见,您需要的是{}
  • 您应该调用animate函数 某处

下面是一个完全有效的示例(Python2.7):

from __future__ import absolute_import, division, print_function, unicode_literals
__metaclass__ = type

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.animation import Animation


Builder.load_string(b'''
<RootWidget>:
    lbl: label
    Label
        id: label
        text: "Welcome"
''')


class RootWidget(Screen):
    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)
        self.animate()

    def animate(self):
        anim = Animation(opacity=0, duration=2)
        anim.start(self.lbl)


class TestApp(App):
    def build(self):
        return RootWidget()


if __name__ == '__main__':
    TestApp().run()

相关问题 更多 >