Kivy:检查功能是否已经安排好 [英] Kivy: Check if a function is already scheduled

查看:70
本文介绍了Kivy:检查功能是否已经安排好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查功能是否已经安排好?我正在查看Clock方法,但没有看到我可以使用的任何东西.我正在尝试避免对函数进行重新调度(Clock.unschedule(func)-> Clock.schedule_interval(func, dt)),除非已经开始对其进行调度.

Is there a way to check if a function has been scheduled already? I was looking at the Clock methods but didn't see anything I could use. I am trying to avoid a rescheduling(Clock.unschedule(func) -> Clock.schedule_interval(func, dt)) of a function unless it is already scheduled to begin with.

推荐答案

您可以使用kivy.clock.Clock.get_events()获取预定事件的列表:

You can use kivy.clock.Clock.get_events() to get the list of scheduled events:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

from kivy.lang import Builder

Builder.load_string("""
#:import Clock kivy.clock.Clock

<MyWidget>:
    Button:
        text: "Print events"
        on_press: print(Clock.get_events())
    Button:
        text: "Add event"
        on_press: Clock.schedule_once(root.my_callback, 5)
""")

class MyWidget(BoxLayout):
    def my_callback(self, arg):
        print("my_callback")

class MyApp(App):
    def build(self):
        return MyWidget()

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

旧答案:

不是很干净的方法,但是您可以检查kivy.clock.Clock._events列表的内容.

Not a very clean way, but you can examine the content of kivy.clock.Clock._events list.

这篇关于Kivy:检查功能是否已经安排好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆