3

I'm trying to make a square with python. Here's the code:

import turtle

def draw_square():

    window = turtle.Screen()
    window.bgcolor("red")

    brad = turtle.Turtle()
    brad.shape("turtle")
    brad.color("yellow")
    brad.speed(2)

    brad.forward(100)
    brad.right(90)
    brad.forward(100)
    brad.right(90)
    brad.forward(100)
    brad.right(90)
    brad.forward(100)
    brad.right(90)


    window.exitonclick()
draw_square()

But I get this error:

File "C:/Python27\turtle.py", line 4, in draw_square
  window = turtle.Screen()
AttributeError: 'module' object has no attribute 'Screen'
zondo
  • 19,901
  • 8
  • 44
  • 83
andrei
  • 31
  • 1
  • 4
  • 1
    You named your file `turtle.py` Rename it to something else and try again. If you also have `turtle.pyc`, remove that too. – zondo Mar 29 '16 at 14:26

1 Answers1

4

you called your file turtle.py so you end up importing your own file instead of the module, rename it and remove the .pyc files (possibly in a __pycache__ folder) and you should be good to go.

Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
  • Thanks! But how do I rename the file? Besides .py, there is .txt. I tried it, but it still doesn't work – andrei Mar 29 '16 at 14:37
  • @andrei: Your script's extension should be `.py`. May I suggest `turtle_square.py` for a file name? – PM 2Ring Mar 29 '16 at 14:48
  • Got it brother! :) Thank you so much. Apparently I had to delete all the other files that were saved so far for this project. And then I renamed it to my_turtle. – andrei Mar 29 '16 at 14:51