6

I am trying to run this code in pycharm:

import tkinter as tk

root = tk.Tk()

w = tk.Label(root, text="Hello, world!")
w.pack()

root.mainloop()

However it always gives me the following errror:

Traceback (most recent call last):
  File "/home/nils/PycharmProjects/rfid/first_test.py", line 1, in <module>
    import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'

If I use the same exact code in IDLE, it works perfectly. I just can not figure out how to install/import tkitner (through the project interpreter didnt work). I am using python 3.7 and the newest Linux Mint.

If you could provide me some hints or a solution, it would be very much appreciated :D

Thanks!

Edit: Typing in " import tkinter " in the IDLE shell works fine, however typing in the same in the PyCharm console produces the error above...

Edit2: I solved the problem by completly uninstalling pycharm and installing it again.

bitbyte
  • 119
  • 2
  • 8

2 Answers2

2

If you're here and have issues on macOS Big Sur, and use Homebrew know that tkinter is not included with Python 3.9, and needs to be installed separately.

brew install python-tk@3.9
John Johnson
  • 140
  • 10
0

You can right click it and go to context actions to install or go to the terminal and type, pip install python-tkinter or sudo apt install python-tkinter!