ImportError: No module named 'Tkinter'

For some reason, I cannot use the Tkinter or tkinter . After running the following command in python shell

 import Tkinter 

or

 import tkinter 

I got this error

ModuleNotFoundError: no module named 'Tkinter'

or

ModuleNotFoundError: no module named 'Tkinter'

What could be the reason and how can we solve it?

+156
python tkinter
Sep 18 '14 at 6:19 06:19
source share
4 answers

You probably need to install it

 sudo apt-get install python3-tk 

I have been using Tkinter for a long time. Why don't you try it and let me know if it worked?

 try: # for Python2 from Tkinter import * ## notice capitalized T in Tkinter except ImportError: # for Python3 from tkinter import * ## notice lowercase 't' in tkinter here 

Here is the link to the link and here is the document

Better check out the versions as suggested here :

 if sys.version_info[0] == 3: # for Python3 from tkinter import * ## notice lowercase 't' in tkinter here else: # for Python2 from Tkinter import * ## notice capitalized T in Tkinter 

Or you will get an ImportError: No module named tkinter

+263
Sep 18 '14 at 6:26
source share

Since you are using Python 3, the module has been renamed to tkinter , as stated in the documentation :

Note. Tkinter has been renamed tkinter in Python 3. The 2to3 tool automatically adapts the import when converting your sources to Python 3.

+59
Sep 18 '14 at 6:27
source share

For Windows 10 using either VSCode or PyCharm with Python 3.7.4 - make sure Tk is checked during installation. I tried import tkinter as xyz with upper / lower t and k and all options without luck.

What works:

 import tkinter import _tkinter tkinter._test() 

Example in action:

 import tkinter import _tkinter HEIGHT = 700 WIDTH = 800 root = tkinter.Tk() canvas = tkinter.Canvas(root, height = HEIGHT, width=WIDTH) canvas.pack() frame = tkinter.Frame(root, bg='red') frame.pack() root.mainloop() 
+2
Sep 07 '19 at 3:29
source share

check the Python version you installed using the python --version command

verify the installation of the Tk module from the following code

 sudo apt-get install python3-tk 

Check if you are using an open source OS, then

check the tkinter module on the following path / home / python / site-packages / tkinter change the path according to your system

+1
Jul 24. '19 at 9:56
source share



All Articles