当我尝试导入乌龟时,我一直收到错误

时间:2014-03-25 18:26:06

标签: python turtle-graphics

import turtle
window = turtle.screen()
myTurtle.forward(100)
myTurtle.left(90)
myTurtle.forward(100)

window.mainloop()

当我尝试使用上面的代码并且不确定原因时,我收到此错误,因为它与我的讲师幻灯片放映一样,我只想自己测试一下。

Traceback (most recent call last):
File "/Users/ruairimangan-cliff/Desktop/Foundations of Computer Programming/week 4/Week 4 'Functions'.py", line 72, in <module>
window = turtle.screen()
AttributeError: 'module' object has no attribute 'screen'

2 个答案:

答案 0 :(得分:4)

确保您好好阅读错误!单个拼写错误/错误输入的资本可能导致这样的错误!

更改:

window = turtle.screen()

到:

window = turtle.Screen()

http://openbookproject.net/thinkcs/python/english3e/hello_little_turtles.html

答案 1 :(得分:4)

我也有这个问题。事实证明我命名了我的文件turtle.py,它与模块冲突。一旦我将其命名为别的东西,它就会再次开始工作。