0
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'
unor
  • 92,415
  • 26
  • 211
  • 360
user3382238
  • 143
  • 1
  • 2
  • 11
  • The first thing that should stick out to you is that you haven't defined the variable myTurtle. The second thing that sticks out to me is that you define the variable window, but then never use it. Is that statement really needed? (it's possible that calling turtle.screen(), or turtle.Screen() as suggested below has side effects, though I doubt it). Honestly, I'm here because I can't get any example from any of the pages I've found for the python turtle module to work. My Python is version 3.7.4 on Windows 10, installer obtained from the main python web site. Very frustrating. – John Deighan Aug 09 '19 at 01:02

3 Answers3

7

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.

Slothario
  • 2,830
  • 3
  • 31
  • 47
4

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

flakes
  • 21,558
  • 8
  • 41
  • 88
4

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

Community
  • 1
  • 1
feargal
  • 2,655
  • 2
  • 22
  • 27