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'

5 comments

Duplicates support request in Zendesk.

0

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?

0

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).

0

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

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

0

Please sign in to leave a comment.