Python龟:对象没有属性'Turtle'

时间:2018-04-13 10:52:54

标签: python-2.7 module turtle-graphics

这是我的代码:

import turtle 
e = turtle.Turtle
e.speed(10)
d = 100
angle = 140
for i in range (1, 1000):
    e.forward(d)
    e.left(angle)
    d = d - 1

当我运行代码时,弹出这个东西。

Traceback (most recent call last):
  File "C:\Users\User\Desktop\Python\TUrtle graphic.py", line 2, in <module>
    e = turtle.Turtle
AttributeError: 'module' object has no attribute 'Turtle'

1 个答案:

答案 0 :(得分:0)

而不是:

e = turtle.Turtle

你需要这样做:

e = turtle.Turtle()

完整代码:

import turtle

e = turtle.Turtle()
e.speed(10)
d = 100
angle = 140

for i in range(1, 1000):
    e.forward(d)
    e.left(angle)
    d = d - 1

turtle.mainloop()

请注意,d最终会变为否定,因此您的forward将在大多数迭代中有效地成为backward