社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Vladimir Moskalenko • 5 年前 • 1516 次点击  

我在编写python并尝试使用turtle,但它给了我这样的响应:

    [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'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49927
 
1516 次点击  
文章 [ 2 ]  |  最新文章 5 年前
cdlane
Reply   •   1 楼
cdlane    5 年前

您的代码正确:

import turtle
t = turtle.Pen()

确保你没有自己的文件 turtle.py 因为这会干扰Python自己的加载 乌龟.py 图书馆。

Derek Eden
Reply   •   2 楼
Derek Eden    5 年前

钢笔里没有大写字母。。。

它是:

import turtle
turtle.pen()

试着做 dir(turtle) 要查看可用功能的列表,在其中您将看到pen

my shell