Python错误:模块“ turtle”没有属性“ Pen”

时间:2019-11-18 03:50:50

标签: python turtle-graphics

我正在尝试在 test1 = [a,1,x] test2 = [b,2,y] 编程中使用 first_alpha = [a,b] number = [1,2] last_alpha = [x,y] 模块的Pen功能,但这给了我这个错误:

turtle

2 个答案:

答案 0 :(得分:1)

您的代码是正确的:

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'”。

答案 1 :(得分:0)

笔头没有钱...

是:

import turtle
turtle.pen()

尝试做dir(turtle)来查看可用功能的列表,在那里您将看到笔

my shell