ImportError: No module named 'Tkinter'

For some reason, I can't use the Tkinter or tkinter module. After running the following command in the 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 for and how can we solve it?

I have been using Tkinter for a while now. 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 is the doc

Better to check 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 error 'ImportError: No module named tkinter'

EDIT 1:

On linux distro try the following and let me and others know by upvoting the answer if it worked for you for Python3.

    sudo apt-get install python3-tk

From: stackoverflow.com/q/25905540

Back to homepage or read more recommendations: