Robotica
Robotica

Reputation: 85

Cannot import Tkinter on visual studio code?

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.

Upvotes: 5

Views: 17549

Answers (4)

Stutya Patwal
Stutya Patwal

Reputation: 1

When you were installing python there is a option. Install tkinter and ide just check it and then reinstall python after that close and open vs code. Here you go!

Upvotes: -1

Omidoo
Omidoo

Reputation: 513

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"

Upvotes: -1

kyle bentley
kyle bentley

Reputation: 29

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

Upvotes: 2

code11
code11

Reputation: 2309

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.

Upvotes: 0

Related Questions