python-3.x - python:kivy动画计数执行
问题描述
编程新手,我似乎无法计算动画执行了多少次,我希望能够在动画执行/完成特定次数后关闭它。
类 MainApp(App):计数 = 0
def build(self):
return Builder.load_file("kv_ellipse.kv")
def on_start(self):
print("start")
Clock.schedule_interval(self.animate_the_widget, 1.1)
def animate_the_widget(self, widget, *args):
self.count + 1
print("animate")
widget = self.root.ids.the_blinking_button
anim = Animation(animated_color=(0, 0, .5, 0), blink_size=200)
anim.bind(on_complete = self.counter)
anim.start(widget)
def reset(self, *args):
print("reset")
widget = args[1]
widget.animated_color = (.1, .4, .4, 1)
widget.blink_size = 5
def counter(self, *args):
self.reset(self.count + 1)
print('counter', self.count)
MainApp().run()
解决方案
首先将时钟计划设置为类属性,以便稍后取消计划。
self.clock = Clock.schedule_interval(self.animate_the_widget, 1.1)
然后,当你在 python 中增加一个计数器时,这样做。
self.count += 1
然后稍后您可以检查此计数器并取消计划。
if self.count > 9:
Clock.unschedule(self.clock)
# and / or do whatever you need here.
#If it's just to stop the app, exit() is enough.
exit()
推荐阅读
- kubernetes - 使用 Helm 部署 GitLab。Nginx-ingress pod 无法启动
- jboss - 设置或更新 JBPM6 流程变量的正确方法
- apache - 本地 SSL 证书返回错误“结果太小”、“获取密码问题”
- ruby-on-rails - Rails Where vs Join vs Union
- python-3.x - 如何使 OrderedSet 可腌制?
- java - 我的 IDE 无法识别 Java 中的 Array.sort
- reactjs - 数组或迭代器中的每个孩子都应该有一个唯一的“key”道具。检查 `Abstractfactory` 的渲染方法
- java - 如何在 imageView 上正确放置多个 TextView
- twitter-bootstrap - 带有延迟弹出菜单的 Bootstrap 3 导航栏链接
- acumatica - 在处理库存问题(发货)之前处理客户发票