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.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Robotica
  • 75
  • 1
  • 1
  • 8
  • are you using `venv`? – Moshe Slavin Sep 13 '18 at 16:25
  • @MosheSlavin no. At least I haven't told it to create a virtual environment. – Robotica Sep 13 '18 at 16:28
  • are you aware it's `Tkinter` in python 2, and `tkinter` in python 3? – Bryan Oakley Sep 13 '18 at 16:49
  • @BryanOakley yeah I am using python 3, and I have been importing it as tkinter, the only reason I did the try/except with the python2 syntax was to see if my IDE was for some reason going by python2. – Robotica Sep 13 '18 at 16:55
  • Does this answer your question? [Why does tkinter (or turtle) seem to be missing or broken? Shouldn't it be part of the standard library?](https://stackoverflow.com/questions/76105218/why-does-tkinter-or-turtle-seem-to-be-missing-or-broken-shouldnt-it-be-part) – Karl Knechtel Apr 28 '23 at 20:47

4 Answers4

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,731
  • 22
  • 33
  • 46
0

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,986
  • 5
  • 29
  • 37
-1

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
  • 493
  • 1
  • 6
  • 14
  • "Your interpreter" is not "PHP" anything for Python code. Aside from that, OP already recognized this difference, accounted for it, and tried both versions anyway. – Karl Knechtel Apr 28 '23 at 20:46
-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!

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 30 '22 at 18:13