PyCharm Turtle Help!

Completed

I am fairly new to Python and PyCharm and i am currently learning about turtle, but i am not able to use it in Pycharm. I have tried 'import turtle' and then written some code after but all i am getting back is an error message. I i go to IDLE and run the code in that it works but i would much prefer to use PyCharm. If anyone could help me out i would really appreciate it!

 

P.S.

This is the error message i am getting

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

2
7 comments

Duplicates support request in Zendesk.

0
Avatar
Permanently deleted user

Not sure what Zendesk is, but I'm having the same problem.  I'm paying for this product and IDLE Python is free.  I can use turtle from IDLE Python with no problem at all.  The import statement doesn't fail, but I am unable to use any of the turtle methods without error.  Uses the same interpreter as IDLE Python, so what's the deal?

1

Could you please attach a screenshot with this error in PyCharm? Please, also show your project tree on this screenshot (a left pane with your project files).

1
Avatar
Permanently deleted user

Odd, with all the reference errors, I was still able to successfully run the script.  I still would like to have the code completion and get rid of the reference errors; I imagine they are directly related.

0
Avatar
Permanently deleted user

The problem is in \Lib\turtle.py.

Magic variable __all__ is defined as follows:

__all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
_tg_utilities + ['Terminator']) # + _math_functions)

And PyCharm does not execute this code while scanning packages. So PyCharm can not define which functions can be used in module-level.

So you can change turtle.py:

# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
# _tg_utilities + ['Terminator']) # + _math_functions)
__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back',
'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen',
'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen',
'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp',
'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto',
'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease',
'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset',
'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx',
'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt',
'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']

Also you can use Turtle class:

T = turtle.Turtle()
T.color('red')
etc

1

https://www.youtube.com/watch?v=8DEHcYvesXY 

 

you can watch this youtube video hope it helps. 

0

Pycharm turtle problem solution

The problem is in your file name yes ! In your file name
1st rename the file other than the turtle.py
For ex example.py than run the example.py then it will definitely works fine in pycharm .
but

don't use the run button as it will run the previous file

0

Please sign in to leave a comment.