Reputation: 803
I have a simple tkinter callback that scrubs forward through a video when a key is pressed or held down.
root.bind('<Right>', callback_scrubFwd)
root.mainloop()
This plays back the video very nicely. How can I trigger this callback to be called continuously, which is what happens when the key is held down by the user, only automatically? I've tried ordinary while
loops or nested/timed function calls but these lock up the interface.
Upvotes: 0
Views: 308
Reputation: 386342
If you want a function to run continuously, at the end of the function you can call after
to put another invocation of the callback on the event queue:
def callback_scrubFwd():
<your code here>
root.after(1000, callback_scrubFwd)
If you want to be able to stop the auto-repeat you can add a flag that you check for each time it is called:
def callback_scrubFwd():
<your code here>
if do_autorepeat:
root.after(1000, callback_scrubFwd)
Upvotes: 2