简体   繁体   English

Python Kivy:添加背景循环

[英]Python Kivy: Add Background loop

I want to paste a background loop into my Python-Kivy script. 我想将背景循环粘贴到我的Python-Kivy脚本中。 The problem is, that I've got only a App().run() under my script. 问题是,我的脚本下只有一个App().run() So, if I put a loop, somewhere in the the App-Class, the whole App stopps updating and checking for events. 因此,如果我在应用程序类的某个地方放了一个循环,则整个应用程序都会停止更新并检查事件。 Is there a function name like build(self) , that's recognized by Kivy, and represents a main/background-loop? 是否有一个像build(self)这样的函数名,它被Kivy识别并表示一个主/后台循环?

If you don't know, what I'm talking about, feel free to ask. 如果您不知道我在说什么,请随时提问。

In case you need to schedule a repeated activity in a loop, you can use Clock.schedule_interval() to call a function on a regular schedule: 如果您需要安排一个循环中的重复活动,可以使用Clock.schedule_interval()定期调用一个函数:

def my_repeated_function(data):
    print ("My function called.")

Clock.schedule_interval(my_repeated_function, 1.0 / 30) # no brackets on function reference 
                                                       # call it 30 times per second

There is a lot more information on how to schedule events on a regular, conditional or one-time basis with Kivy's event loop here . 有关于如何安排与Kivy的事件循环有规律,有条件的或一次性的事件更多的信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM