此代码应利用鼠标移动事件在当前鼠标位置绘制一个点:
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)
如果鼠标移动得很慢,代码会按预期工作几秒钟或更长时间。然后它抛出:
>>>
====================== 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
===============================
>>>
任何帮助深表感谢。
慕容3067478
相关分类