user3382238
user3382238

Reputation: 141

i keep getting an error when i try and import turtle

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'

Upvotes: -1

Views: 16506

Answers (3)

John von No Man
John von No Man

Reputation: 3030

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.

Upvotes: 7

feargal
feargal

Reputation: 2735

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

Upvotes: 4

flakes
flakes

Reputation: 23684

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

Upvotes: 4

Related Questions