gpt4 book ai didi

python - Kivy 标签文本淡入

转载 作者:太空宇宙 更新时间:2023-11-04 04:56:11 25 4
gpt4 key购买 nike

我正在尝试使用 kivy 中的动画工具使标签中的一些文本淡入淡出,但我无法让它工作,而且我在互联网上找不到任何帮助。继承人的代码:

.py:

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

.kv

<TestScreen>
lbl: label
Label
id: label
text: "Welcome"

最佳答案

  • Animate更改为Animation
  • opacity=1表示标签可见,你要的是opacity=0
  • 你应该调用animate函数某处

这是完整的工作示例(Python 2.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()

关于python - Kivy 标签文本淡入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47001224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com