Home > Software engineering >  why tkinter error rise when using turtle on pycharm
why tkinter error rise when using turtle on pycharm

Time:09-06

I'm new to Python, so I'm trying some turtle basic codes using PyCharm IDE but this error keep raising

Traceback (most recent call last):
  File "/Users/amerm/Desktop/CP_1/Turtle_new.py", line 1, in <module>
    import turtle
  File "/usr/local/Cellar/[email protected]/3.9.13_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 107, in <module>
    import tkinter as TK
  File "/usr/local/Cellar/[email protected]/3.9.13_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

the code is

t_1 = turtle.Turtle()

t_1.speed(1)

t_1.forward(100)
t_1.left(45)
t_1.forward(100)

turtle.done()

CodePudding user response:

The error is saying

If this fails your Python may not be configured for Tk

Since you've evidently (/usr/local/Cellar is the smoking gun evidence) installed Python from Homebrew, you'll also have to install the tk package separately:

brew install [email protected]

and try again.

  • Related