Is there any difference between window.listen()
, screen.listen()
, and turtle.listen()
?
I see them used differently in various programs but assume they can be called interchangeably.
Best Answer
I suggest you read Difference between turtle and Turtle?. The short answer is that the turtle library provides two API's, a function-based one and an object-oriented one. (Behind the scene, the function one is built atop the object one at load time.) The confusion begins when you mix the two. My answer in the link explains one way to avoid doing so.
turtle
and screen
have separate inputs.
For example:
turtle.onclick()
and screen.onclick()
may seem the same but screen.onclick()
is referring to the general window while turtle.onclick()
is referring to the turtle module itself.
Turtle
When calling turtle.onclick()
you are activating the (onclick
) function, to call your argument function whenever the user clicks specifically on the turtle object.
Screen
When calling screen.onclick()
you are activating the (onclick
) function, to call your argument function whenever the user clicks anywhere on the window.
This is equivalent to turtle.onscreenclick()
because onscreenclick()
refers to the entire screen. Hence the name screenclick
rather than just click
which refers to the turtle object.
Listen
So because turtle
and screen
have separate input functions, you'll need separate listening functions.
So
turtle.listen()
listens for overall the entire turtle module's inputs, whilst screen.listen()
listens for screen / window inputs.