I want to loop and call a function every 1000 milliseconds with wx.CallLater.

Hi, please can you help! Thanks.

I want to loop and call a function every 1000 milliseconds with wx.CallLater. I implemented this (see below), but it does not factor in the delay - it seems to execute automatically. How can I get this to wait 1000 milliseconds between function calls?

This function is within a class. In my main module, I instantiate an object of this class and call the task_loop function. I intend to keep the loop going until will_break is set to True, and task_loop returns the work_session_agenda in the main module. Thank you for your help!

def task_loop(self, duration, window, task, work_session_agenda, start, completed):

will_break = False

will_continue = False

duration -= datetime.timedelta(seconds=1) More code in here - which, depending on conditionals, sets the values of will_break and will_continue

if will_break:

print(‘BREAKING’)

return work_session_agenda

else:

print(‘GOT HERE’)

timer = wx.CallLater(1000, self.task_loop, duration, window, task, work_session_agenda, start, completed)

Have you looked into the sleep() function as an option?

sleep () doesn’t work for GUIs because it disrupts the main loop. Thank you!

1 Like