Question

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

window.mainloop()

I get this error when I try and use the code above and not sure why, because its the same as my lecturers slide show, I just wanted to test it for myself.

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'
Était-ce utile?

La solution 2

Make sure you read your errors well! A single typo/ mistyped capital can cause errors like this!

Change :

window = turtle.screen()

to :

window = turtle.Screen()

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

Autres conseils

I had this problem, too. Turns out I named my file turtle.py, which conflicted with the module. As soon as I named it something else it started working again.

Alternatively if you have the same problem but don't have a typo in

window = turtle.Screen()

but you are still getting the error msg:

AttributeError: 'module' object has no attribute 'Screen'

Is your script called turtle.py?

If so it is taking precedence over the turtle module in the standard library. Rename your script á la this answer

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top