Turtle not working on Python in PyCharm for Mac - screen just flickers before error code shows up

Viewed 604

I am trying to use Turtle using the code below but when the window pops up nothing happens and screen.exitonclick() also doesn't work. The screen just flickers for a few seconds and stops. Any ideas?

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")
timmy_the_turtle.color("red")
timmy_the_turtle.forward(100)
timmy_the_turtle.right(90)

screen = Screen()
screen.exitonclick()

I am then getting the following errors:

Traceback (most recent call last):
  File "/Users/Work/PycharmProjects/Day18/main.py", line 5, in <module>
    timmy_the_turtle.color("red")
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/turtle.py", line 2217, in color
    pcolor = self._colorstr(pcolor)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/turtle.py", line 2697, in _colorstr
    return self.screen._colorstr(args)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/turtle.py", line 1159, in _colorstr
    raise TurtleGraphicsError("bad color string: %s" % str(color))
turtle.TurtleGraphicsError: bad color string: red
2 Answers

I would check if it works in i.e. IDLE. If it works, then it is a PyCharm problem. Try reinstalling it. If it doesn't work, try adding a turtle.done() (not the turtle name, just the module turtle) after the turtle has moved.

I had exactly the same problem. I discovered that my PyCharm interpreter was set to use Python 2.7. I changed it to use Python 3.10, and that solved the problem.

Related