Getting "maximum Recursion Depth Exceeded" With Python Turtle Mouse Move
This code should utilize mouse motion events to draw a dot at the current mouse position: import turtle  def motion(event):     x, y = event.x, event.y     turtle.goto(x-300, 300-y
Solution 1:
The problem is that a new event comes in while your event hander is still processing the previous event, so the event handler gets called from inside the event handler which looks like a recursion! The fix is to disable the event binding while inside the event handler:
from turtle import Screen, Turtle
def motion(event):
    canvas.unbind("<Motion>")
    turtle.goto(event.x - 300, 300 - event.y)
    turtle.dot(5, "red")
    canvas.bind("<Motion>", motion)
screen = Screen()
screen.setup(600, 600)
turtle = Turtle(visible=False)
turtle.speed('fastest')
turtle.penup()
canvas = screen.getcanvas()
canvas.bind("<Motion>", motion)
screen.mainloop()
Post a Comment for "Getting "maximum Recursion Depth Exceeded" With Python Turtle Mouse Move"