由于“未定义宽度错误”,我无法将海龟模块导入python 2.7.10

时间:2015-08-07 00:31:00

标签: python module width turtle-graphics

所以我将这个代码从我的在线课程复制粘贴到我的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

1 个答案:

答案 0 :(得分:1)

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