在Kivy中脉动背景色 [英] Pulsing Background Color in Kivy
本文介绍了在Kivy中脉动背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新手,但是我真的坚持了.有什么办法可以在画布上具有类似于CSS中这种效果的Pulsing背景:
I'm new to kivy, but I really stuck on this. Is there any way to have a Pulsing background on a canvas similar to this effect in CSS:
https://codepen.io/LukeAskew/pen/gabgom
body {
background-color: #222;
animation-name: color;
animation-duration: 2s;
animation-iteration-count: infinite;
}
@keyframes color {
0% {
background-color: #222;
}
50% {
background-color: #4285f4;
}
100 {
background-color: #222;
}
}
是否有可能使用基维做类似的事情?
Is it even possible to do something like this using kivy?
推荐答案
您可以使用 kivy.Animation
为背景色设置动画:
You can use kivy.Animation
to animate the background color:
from kivy.animation import Animation
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
class Pulser(Widget):
bg_color = ObjectProperty([1, 1, 1, 1])
def __init__(self, **kwargs):
super(Pulser, self).__init__(**kwargs)
Clock.schedule_once(self.start_pulsing, 2)
def start_pulsing(self, *args):
anim = Animation(bg_color=[1,0,0,1]) + Animation(bg_color=[1,1,1,1])
anim.repeat = True
anim.start(self)
theRoot = Builder.load_string('''
Pulser:
canvas:
Color:
rgba: self.bg_color
Rectangle:
pos: self.pos
size: self.size
''')
class PulserApp(App):
def build(self):
return theRoot
if __name__ == "__main__":
PulserApp().run()
这篇关于在Kivy中脉动背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文