0

I tried importing the Tkinter module in Visual Studio Code while writing code for UI development. I'm getting the following error:

ModuleNotFoundError: No module named 'Tkinter'

Do I have to do a pip install for this module? Also, how do I do that in VSC?

pcampana
  • 2,413
  • 2
  • 21
  • 39
james matt
  • 11
  • 1
  • 3
  • If you are using `Tkinter` instead of `tkinter` it won't work. The "t" should be in small letters while importing `tkinter`. Like This: `import tkinter as tk` – DaniyalAhmadSE Apr 09 '20 at 12:40

1 Answers1

1

Which python version are you using? Tkinter should come with Python. You can allways try

python -m tkinter

That should open an exemplary window (reference). Further you could also just try to pip install tkinter

In python modules (packages) are managed with pip. Pip is indepent of your IDE (in your case visual studio) you can call it from the console. See here

pip --version
python -m ensurepip --default-pip

Edit
I have a guess what the problem is. Your python version is not correctly in your PATH variable. Check this link . While installing python you probably unticked the check box to add python to your path. Here is also a step by step to fix this

Björn
  • 1,610
  • 2
  • 17
  • 37
  • Currently using version 3.7.4 – james matt Apr 09 '20 at 07:07
  • I am getting this after trying to pip install tkinter : PS C:\Users\HP> pip install Tkinter pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + pip install Tkinter + ~~~ + CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – james matt Apr 09 '20 at 07:20
  • You need to be careful with the spelling `tkinter` needs to be written completely in small caps – Björn Apr 09 '20 at 07:25
  • Since Python Version 3.4 it does come also with pip already installed. Please try the following in command line `python -m pip install tkinter` – Björn Apr 09 '20 at 07:26