The standard way to end ontimer()
in Python Turtle Graphics is to simply not repeat calling it, based on some condition.
In my use case however, I need to actively kill the timer.
The relevent part of code from the turtle
module is:
def _ontimer(self, fun, t):
"""Install a timer, which calls fun after t milliseconds.
"""
if t == 0:
self.cv.after_idle(fun)
else:
self.cv.after(t, fun)
This answer explains how to destroy a timer using pure python tkinter
. I found the after
method in turtle._Root
but I can't see how to get access to the id
for it, or figure out exactly how I would use it if I had it.
Any help much appredciated.
Here's a sample program I would like to apply the solution to:
import turtle
turtle.shape("turtle")
def move():
turtle.fd(20)
turtle.ontimer(move, 500)
move()
turtle.done()