5

Ok, I am having a weird issue going on. From what I understand Tkinter is supposed to be built in with python 2 and 3.

I can import and use Tkinter just fine in my terminal under python3 as well as with IDLE3. However, when I try to import Tkinter in Visual Studio Code I get an "ImportError: No module named 'tkinter'.

The same issue was happening in Pycharm also but I had my interpreter set to the same as my terminal and not a project-specific interpreter.

I have tried the following:

import tkinter
from tkinter import *
try:
    import tkinter
except ImportError:
    import Tkinter as tkinter #Even though I'm using python3

None of this is working, Any idea why? Also I am using Linux Mint.

Robotica
  • 55
  • 1
  • 7

3 Answers3

2

I've been stuck with the same issue for weeks now where my VSC says there are no tkinter module but in shell and terminal it runs fine.

Solution: I found out that in the left buttom corner there is an interpreter that runs as Python 2 just click and select Python 3

pppery
  • 3,550
  • 19
  • 28
  • 41
1

In windows you could have selected to not install the needed tkinter components when python was installed (its optional in the installer).

Try running the installer again, and make sure these components are selected.

code11
  • 1,780
  • 5
  • 29
  • 35
0

If your interpreter is PHP2 it is spelled "Tkinter" in the code. (uppercase) If your interpreter is PHP3 then you should spell it like "tkinter"

Omidoo
  • 499
  • 1
  • 6
  • 14