我一直在玩 python turtle,我似乎无法让 exitonclick 函数工作,每当我单击窗口试图关闭屏幕时,它都会返回错误。我还尝试删除 mainloop,这会删除错误消息但也不会关闭窗口。
我的代码如下:
import turtle
wn = turtle.Screen()
circle1 = turtle.Turtle(shape = 'circle')
circle1.fd(100)
wn.exitonclick()
wn.mainloop()
错误信息是:
Traceback (most recent call last):
File "/Users/luke/test.py", line 11, in <module>
wn.mainloop()
File "/Users/luke/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 813, in mainloop
TK.mainloop()
File "/Users/luke/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 560, in mainloop
_default_root.tk.mainloop(n)
AttributeError: 'NoneType' object has no attribute 'tk'