我试图在Pen编程中使用turtle模块的Python功能,但它给了我一个错误:
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> t = turtle.Pen()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
t = turtle.Pen()
AttributeError: module 'turtle' has no attribute 'Pen'发布于 2019-11-18 03:55:41
笔里没有大写..。
它是:
import turtle
turtle.pen()尝试执行dir(turtle)以查看可用函数列表,在其中您将看到pen

发布于 2019-11-18 05:06:08
您的代码是正确的:
import turtle
t = turtle.Pen()命令行会话:
% python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> t = turtle.Pen()
>>> exit()
% 确保您没有自己的名为turtle.py的文件,因为这会干扰加载Python自己的turtle.py库:
% touch turtle.py
% python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> t = turtle.Pen()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'turtle' has no attribute 'Pen'
>>> 这会产生与您收到的"AttributeError: module 'turtle' has no attribute 'Pen'“相同的结果。
发布于 2022-05-13 19:29:11
实际解决方案:您安装了不正确的包。你应该安装PythonTurtle
https://stackoverflow.com/questions/58907760
复制相似问题