【问题标题】:I can't import turtle module into python 2.7.10 due to a "width error not defined"由于“未定义宽度错误”,我无法将海龟模块导入 python 2.7.10
【发布时间】:2015-08-07 00:30:59
【问题描述】:

因此,我将在线课程中的这段代码复制粘贴到我的 python 2.7.10 中并运行它。它说宽度没有定义。我试图寻找解决这个问题的问题,但找不到,而且我开始学习编码,所以我不知道如何导入海龟模块而不给我一个错误。

from turtle import *    # loads the turtle library...
width(5)        # make the turtle pen 5 pixels wide
shape('turtle') # use a turtle shape!
forward(100)    # turtle goes forward 100 steps
right(90)       # turtle turns right 90 degrees
up()            # turtle lifts its pen up off of the paper
forward(100)    # turtle goes forward 100 steps
down()          # turtle puts its pen down on the paper
color("red")    # turtle uses red pen
circle(100)     # turtle draws circle of radius 100 
color("blue")   # turtle changes to blue pen
forward(50)     # turtle moves forward 50 steps

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    from turtle import *    # loads the turtle library...
  File "turtle.py", line 2, in <module>
    width(5)        # make the turtle pen 5 pixels wide
NameError: name 'width' is not defined

【问题讨论】:

    标签: python module width turtle-graphics


    【解决方案1】:

    也许您在同一文件夹中有这个或另一个名为 turtle.py 的文件。您应该将文件重命名为其他名称。

    【讨论】:

    • 这也是我的投票。拆解这段代码后,对我来说效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多