adorilson
(Adorilson Bezerra)
April 25, 2025, 6:46pm
1
I’m writing a tutorial with Turtle. I’ve used some snippet code to scaffold the students’ work.
I’ve written pieces of stuff like:
turtle.onkey(None, 'Down')
turtle.ontimer(None, 4000)
Despite None
not being callable, this works fine. Except that ontimer
causes a screen freeze for 4000 ms (in this case).
After a dive into the source code, I found these lines .
# I'd rather use time.sleep(ms*0.001)
self.tk.call('after', ms)
So, this freezing seems like a feature. So, the question is: Why? What’s the reason behind that? Why not just return None
?
And where can I see the call
’s documentation? Is this ‘after’ the same function where these lines are on, or a predefined value for call
?
tunedal
(Henrik Tunedal)
April 25, 2025, 7:09pm
2
That code in Tkinter is a wrapper for Tcl/Tk’s after
command, which is documented in the Tcl manual .
It seems to be basically the same thing as time.sleep
when called without a callback. I don’t know if or why one would be preferable to the other. The comment about rather using time.sleep
was apparently added by Guido van Rossum 30 years ago .
adorilson
(Adorilson Bezerra)
April 26, 2025, 3:53pm
3
Thank you, @tunedal .
Really, after
’s definition makes cleaning you can call it without a callback function:
def after(self, ms, func=None, *args):
However, it isn’t possible on turtle.ontimer
. Might we do something there, at least fix the documentation about None
.