def mainthread(func):
 @wraps(func)
 def delayed_func(*args, **kwargs):
  def callback_func(dt):
   func(*args, **kwargs)
  Clock.schedule_once(callback_func, 0)
 return delayed_func

def mainthread ( func ) : @ wraps ( func ) def delayed_func ( * args , ** kwargs ) : def callback_func ( dt ) : func ( * args , ** kwargs ) Clock . schedule_once ( callback_func , 0 ) return delayed_func
decorator that will schedule the call of the function for the next available frame in the mainthread .