ImportError: No module named 'Tkinter' ImportError: No module named 'Tkinter' python python

ImportError: No module named 'Tkinter'


You probably need to install it using one of (or something similar to) the following:

sudo apt-get install python3-tk 

You can also mention version number like thissudo apt-get install python3.7-tk for python 3.7.

sudo dnf install python3-tkinter

Why don't you try this 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 reference link and here are the docs

Better to check versions as suggested here:

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

Or you will get an error ImportError: No module named tkinter


Just to make this answer more generic I borrowed the following from Devendra Bhat's comment:

On Fedora please use either of the following commands

sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64

or

sudo dnf install python3-tkinter


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

Note Tkinter has been renamed to tkinter in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.


For windows 10, it is important to check in the Python install the optional feature "tcl/tk and IDLE". Otherwise you get a ModuleNotFoundError: No module named 'tkinter'. In my case, it was not possible to install tkinter after the Python install with something like "pip install tkinter"


matomo