Link to home
Start Free TrialLog in
Avatar of geeta_m9
geeta_m9

asked on

Can't get turtle graphics to run from a program file

When using Python, I am able to type  my code into a file using the IDLE editor, save the file and and run the program without any problems.  My output is displayed in the shell. However, when I try to do the same  thing with the turtle graphics, I keep getting an error. For example, I typed the following code into a file to draw a square.

import turtle
t = turtle.Pen()
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)
t.forward(50)
t.left(90)

However, when I tried to run my program, I get the following error:

Traceback (most recent call last):
  File "C:/Users/hdtest/Desktop/turtle.py", line 1, in <module>
    import turtle
  File "C:/Users/hdtest/Desktop\turtle.py", line 2, in <module>
    t= turtle.Pen()
AttributeError: module 'turtle' has no attribute 'Pen'

It seems like it will only work within the shell itself, i.e., interactively.

How can I get it to run as a program?
ASKER CERTIFIED SOLUTION
Avatar of Flabio Gates
Flabio Gates

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geeta_m9
geeta_m9

ASKER

Yes, that worked. Thank you so much!