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)
turtle.dot(5, "red")
turtle.pu()
turtle.setup(600, 600)
turtle.hideturtle()
canvas = turtle.getcanvas()
canvas.bind("<Motion>", motion)
The code works as expected for a few seconds or longer if the mouse is moved very slowly. Then it throws:
>>>
====================== RESTART: C:/code/turtle_move.py
======================
>>> Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1698, in __call__
args = self.subst(*args)
File "C:\Users\...\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1428, in _substitute
e.type = EventType(T)
RecursionError: maximum recursion depth exceeded
=============================== RESTART: Shell
===============================
>>>
Any help is much appreciated.