简体   繁体   中英

Getting clock schedule to start in python kivy app

I can't figure out what's wrong with my code. I've tried several variations, and I can't get Clock to schedule the function12. Please help. Thank you!

import os
os.environ["KIVY_NO_CONSOLELOG"] = "1"
from kivy.app import App
import time
from kivy.clock import Clock

class MainApp(App):

    def on_start(self):
        print("Here")
        Clock.schedule_once(self.function12,5)
        print("Here")
        time.sleep(100)

    def function12(self):
        print("INSIDE")

Your function12() method needs a dt argument, like this:

def function12(self, dt):
    print("INSIDE")

And the scheduled method cannot run until the time.sleep() has completed, since the on_start() method is running on the main thread, and the sleep holds the main thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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