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?
asked Sep 18, 2014 at 6:19
0
You probably need to install it using something similar to the following:
-
For Ubuntu or other distros with Apt:
sudo apt-get install python3-tk
-
For Fedora:
sudo dnf install python3-tkinter
You can also mention a Python version number like this:
-
sudo apt-get install python3.7-tk
-
sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64
Finally, import tkinter
(for Python 3) or Tkinter
(for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
Mark Amery
137k78 gold badges401 silver badges450 bronze badges
answered Sep 18, 2014 at 6:26
d-coderd-coder
12k4 gold badges25 silver badges35 bronze badges
4
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.
answered Sep 18, 2014 at 6:27
Burhan KhalidBurhan Khalid
167k18 gold badges242 silver badges278 bronze badges
0
If you’re using python 3.9 on Mac, you can simply install tkinter
using brew:
brew install python-tk@3.9
This fixed it for me.
Edit:
As mentioned by others, you can also use the general command to install the latest version:
brew install python-tk
answered Apr 10, 2021 at 18:11
P1NHE4DP1NHE4D
9308 silver badges14 bronze badges
1
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»
answered Jan 29, 2020 at 15:43
Andi SchroffAndi Schroff
1,0781 gold badge11 silver badges18 bronze badges
3
To install the Tkinter on popular Linux distros:
Debian/Ubuntu:
sudo apt install python3-tk -y
Fedora:
sudo dnf install -y python3-tkinter
Arch:
sudo pacman -Syu tk --noconfirm
REHL/CentOS6/CentOS7:
sudo yum install -y python3-tkinter
OpenSUSE:
sudo zypper in -y python-tk
bfontaine
17.3k13 gold badges73 silver badges100 bronze badges
answered Feb 20, 2021 at 13:31
amzy-0amzy-0
2852 silver badges5 bronze badges
4
You might need to install for your specific version, I have known cases where this was needed when I was using many versions of python and one version in a virtualenv using for example python 3.7 was not importing tkinter I would have to install it for that version specifically.
For example
sudo apt-get install python3.7-tk
No idea why — but this has occured.
answered May 20, 2020 at 17:31
deManglerdeMangler
4173 silver badges14 bronze badges
0
For Mac use:
brew install python-tk
imxitiz
3,8101 gold badge8 silver badges33 bronze badges
answered Jan 21, 2022 at 21:24
1
Installing Tkinter
python -m pip install tk-tools
or
sudo apt install python3-tk
answered Sep 26, 2021 at 13:11
2
For Windows 10 using either VSCode or PyCharm with Python 3.7.4 — make sure Tk is ticked in the install. I tried import tkinter as xyz
with upper/lower t and k‘s and all variants without luck.
What works is:
import tkinter
import _tkinter
tkinter._test()
An 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()
answered Sep 7, 2019 at 3:29
Jeremy ThompsonJeremy Thompson
59.7k32 gold badges184 silver badges308 bronze badges
4
check the python version you have installed by using command python --version
check for the Tk module installed correctly from following code
sudo apt-get install python3-tk
Check if you are using open-source OS then
check the tkinter module in the following path
/home/python/site-packages/tkinter
change the path accordingly your system
barbsan
3,36811 gold badges21 silver badges28 bronze badges
answered Jul 24, 2019 at 9:56
On CentOS7, to get this working with Python2, I had to do:
yum -y install tkinter
Noting this here because I thought that there would be a pip package, but instead, one needs to actually install an rpm.
answered Feb 3, 2020 at 19:57
Make sure that when you are running your python code that it is in the python3 context. I had the same issue and all I had to do was input the command as:
sudo python3 REPLACE.py
versus
sudo python REPLACE.py
the latter code is incorrect because tkinter is apparently unnavailable in python1 or python2.
answered Nov 28, 2019 at 20:42
3
You just need to install it and import them your project like that :
this code import to command line :
sudo apt-get install python3-tk
after import tkinter your project :
from tkinter import *
answered Dec 8, 2019 at 6:33
1
I resolved my issue in the PyCharm do following
- Install Python Interpreter from https://www.python.org/
- PyCharm > Preferences > Python Interpreter > Add
- Select installed interpreter
- In the run configuration select the newly installed interpreter
I also made a video instruction what I did https://youtu.be/awaURBnfwxk
answered Nov 25, 2021 at 15:50
Dima PortenkoDima Portenko
3,2143 gold badges33 silver badges48 bronze badges
For Windows I had to reinstall python and make sure that while installing in Optional Features I had «tcl/tk and IDLE» enabled.
answered Sep 2, 2022 at 15:45
Tkinter should come with the latest Python, I don’t think it comes with Python2. I had the same problem but once. I upgraded to Python 3.8 Tkinter was installed.
answered Jun 10, 2020 at 14:14
EloniEloni
293 bronze badges
$ sudo apt-get install python3.10-tk
answered Jan 14, 2022 at 10:20
devpdevp
2,4502 gold badges15 silver badges24 bronze badges
tkinter comes with python… uninstall python, reinstall it, you’re done
answered Apr 12, 2020 at 5:54
PythonProgrammiPythonProgrammi
21.7k3 gold badges39 silver badges34 bronze badges
0
if it doesnot work in pycharm you can add the module in the project interpreter by searching in +button python-tkinter and download it.
answered Jul 12, 2020 at 4:27
Check apt for tasks, it may be marked for removed
sudo apt autoremove
Then check and install needed
answered Apr 23, 2020 at 6:02
We can use 2 types of methods for importing libraries
- work with
import library
- work with
from library import *
You can load tkinter using these ways:
-
from tkinter import*
-
import tkinter
answered May 5, 2021 at 11:16
You’ll probably need to install Tkinter.
You can do so like this in the Windows command prompt:
pip install tk
answered Jan 25 at 6:26
try:
# for Python2
from Tkinter import * ## notice capitalized T in Tkinter
except ImportError:
try:
# for Python3
from tkinter import * ## notice lowercase 't' in tkinter here
except:
try:
print "Download Tkinter" ##python 2
except SyntaxError:
print("Download Tkinter") ##python 3
answered Mar 31, 2021 at 2:43
0
If you have pip on your path, you could (in your command prompt) just type
pip install tkinter
Most versions of python already come with tkinter.
answered Feb 8, 2022 at 20:40
1
——— WORKED ON PYTHON 2.7————
Install all below packages
sudo apt-get install git
sudo apt-get install python-tk
sudo apt-get install python-pip
sudo apt install picolisp
sudo -H pip2 install --upgrade pip
sudo pip install -I pillow
sudo apt-get install python-imaging-tk
sudo apt-get install python-tk
answered May 4, 2020 at 11:11
RAHUL RAHUL
234 bronze badges
1
Firstly you should test your python idle to see if you have tkinter:
import tkinter
tkinter._test()
Trying typing it, copy paste doesn’t work.
So after 20 hours of trying every way that recommended on those websites figured out that you can’t use «tkinter.py» or any other file name that contains «tkinter..etc.py». If you have the same problem, just change the file name.
fcdt
2,3315 gold badges12 silver badges26 bronze badges
answered Sep 20, 2020 at 9:38
cmd — terminal
pip install tkinter
answered Jan 22, 2022 at 9:10
1
There’re lot ports of PySimpleGUI, basic one is PySimpleGUI which is tkinter port and all GUI code are based on tkinter module. Some other ports are based on Qt, WxPython, and Remi.
The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)
There’s one path shown in your output of sys.path
,
C:UsersuserAppDataLocalProgramsPythonPython37-32lib
if nothing wrong, you can find the sub-directory tkinter
and something like this,
Directory of C:SoftwarePythonLibtkinter 2020/11/13 上午 04:00 <DIR> . 2020/11/13 上午 04:00 <DIR> .. 2017/06/17 下午 07:57 1,863 colorchooser.py 2017/06/17 下午 07:57 1,302 commondialog.py 2017/06/17 下午 07:57 1,603 constants.py 2017/06/17 下午 07:57 1,555 dialog.py 2017/06/17 下午 07:57 11,809 dnd.py 2017/06/17 下午 07:57 14,981 filedialog.py 2017/06/17 下午 07:57 6,813 font.py 2017/06/17 下午 07:57 3,835 messagebox.py 2017/06/17 下午 07:57 1,868 scrolledtext.py 2017/06/17 下午 07:57 11,847 simpledialog.py 2020/11/13 上午 04:00 <DIR> test 2017/06/17 下午 07:57 79,034 tix.py 2017/06/17 下午 07:57 58,630 ttk.py 2017/06/17 下午 07:57 170,821 __init__.py 2017/06/17 下午 07:57 155 __main__.py 2020/11/21 下午 03:07 <DIR> __pycache__ 14 File(s) 366,116 bytes 4 Dir(s) 45,897,330,688 bytes free
I just installed Pycharm Community 2020.3
yesterday, not install any package from Available Packages
and everything ready.
Posted by Marta on March 27, 2021 Viewed 65130 times
Hey there! This article will explain why you might encounter the error – no module named Tkinter – when you are writing a python program and how you can get around this error.
The Tkinter is a module that provides functionality to create graphical user interfaces. It will enable you to create windows, checkboxes, etc. It is a built-in module; therefore, it is included when you installed python.
So if it’s installed, why is there an error? The reason is the Tkinter module was renamed in Python version 3. In python 2, the module was initially called Tkinter. After that, in python 3, the name of the module changed to tkinter
(lowercase).
Is the tkinter module installed? how to check
Firstly, let’s see how to check if the tkinter is installed with python. You can do so by running the following command from your terminal:
In case you have several python installations on your laptop, make sure you are using the correct one when running the command. For instance, in my case, I have two installations, python 2 and python3.
And when I run the command to check if tkinter is installed I see the following:
Output:
/usr/local/opt/python@2/bin/python2.7: No module named tkinter.__main__; 'tkinter' is a package and cannot be directly executed
This means that when I run the python
command on my machine, I am using version 2. So if tkinter
is a built-in module, why is there an error indicating it can’t find thetkinter
module? The reason is the tkinter
module is actually called Tkinter
(uppercase) in python2.
In other words, module names in Python are case sensitive, and in the case of the tkinter module, the module name was initially named Tkinter
in version 2, and changed to tkinter
in Python version 3.
You can check the python version running on your machine by running the below command from your terminal:
Output:
Consequently if I run the same command but using python3, the tkinter sample window will open. See the command below:
Output:
If this window pops up, it means the tkinter module is included in your python installation.
Fix – no module named tkinter error
The easiest way to fix this problem is by upgrading your python to use python 3. If upgrading python is not an option, you only need to rename your imports to use Tkinter
(uppercase) instead of tkinter
(lowercase).
Check if Tkinter is available in python 2 running the following command from your terminal:
Output:
As a result, this window proves that your python installation includes the Tkinter module.
Conclusion
In conclusion, if the error no module named tkinter raises, it probably means you are using python 2. Firstly, you can get around the problem by upgrading to python 3.
Additionally, you can rename your import to Tkinter
, which is how the module was named in python 2, just if upgrading is not an option.
I hope this article was useful, and thanks for reading and supporting this blog. Happy coding! 🙂
More interesting articles
Windows 10
Python 3.7.4
OSGeo4W Shell
C:ActiveTclbin
is in the PATH
tkinter folder is located in C:/OSGeo4W64/apps/Python37/lib/tkinter
python test_data_analysis.py
Traceback (most recent call last):
File "test_data_analysis.py", line 4, in <module>
from matplotlib import pyplot
File "C:OSGEO4~1appsPython37libsite-packagesmatplotlibpyplot.py", line 2355, in <module>
switch_backend(rcParams["backend"])
File "C:OSGEO4~1appsPython37libsite-packagesmatplotlibpyplot.py", line 221, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "C:OSGEO4~1appsPython37libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:OSGEO4~1appsPython37libsite-packagesmatplotlibbackendsbackend_tkagg.py", line 1, in <module>
from . import _backend_tk
File "C:OSGEO4~1appsPython37libsite-packagesmatplotlibbackends_backend_tk.py", line 6, in <module>
import tkinter as tk
File "C:OSGEO4~1appsPython37libtkinter__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
under py3_env I have attempted importing:
_tkinter
tkinter
_Tkinter
Tkinter
importing tk
works.
Oddly enough, when I run from the Python 3.7.4 shell import tkinter
works, but import tk
does not.
Running python -m (all tkinter varieties)
does not work.
Running python -m pip install (all tkinter varieties)
does not work.
I’m on the struggle bus with this one. Any suggestions that are for Windows would be great.
Thread Rating:
- 0 Vote(s) — 0 Average
- 1
- 2
- 3
- 4
- 5
No module named ‘Tkinter’ |
Jun-30-2020, 07:57 AM I’m a beginner, and from my first steps, I have a strange problem. No matter what I have done (google it, set a virtual environment, reinstalling the language several times, installing deferent versions of the language) when I’m trying to give the code: from future.moves import Tkinter as tk window = tk.tk() # to rename the title of the window window.title("GUI") # pack is used to show the object in the window label = tk.label(window, text = "Welcome to DataCamp's Tutorial on Tkinter!").pack() It gives me the following error:
All that, after I have tried with pip in the CMD to install the module. jdos
Posts: 14 Threads: 4 Joined: Jun 2020 Reputation: Jun-30-2020, 08:06 AM
Have you tried from future.moves import tkinter as tk window = tk.Tk() as capitalization matters, I tried that with tkinter and works just fine (well it does load the library) so it should be from future.moves import tkinter as tk window = tk.Tk() # to rename the title of the window window.title("GUI") # pack is used to show the object in the window label = tk.Label(window, text = "Welcome to DataCamp's Tutorial on Tkinter!").pack() Posts: 354 Threads: 13 Joined: Mar 2020 Reputation:
@jdos, your solution gives an excellent explanation, but the real problem is that he doesn’t have the Tkinter module installed. Posts: 11 Threads: 4 Joined: Jun 2020 Reputation: In the first time, I installed it in D drive, now besides I reinstalled my python in my C drive (during the installation some shadows were telling me that some packages won`t be installed)but IntelliJ keeps looking at D:, it still gives me an error:
On the other side, it is still not recognizing the «Tkinter» module : import TKinter Telling me that the module still doesn`t exist. Posts: 101 Threads: 5 Joined: Jul 2019 Reputation:
Did you update your Python path with the latest one? And map your current Python path to the editor as well. Try running PIP command from the latest path Posts: 98 Threads: 1 Joined: Dec 2019 Reputation: You may still have other issues but as jdos mentioned you need to use «tkinter» for python 3. «Tkinter» is for python 2. There is an example of how to detect the python version in this thread: «So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!» — Tim the Enchanter Posts: 5 Threads: 3 Joined: Jun 2020 Reputation: Have u named your py file tkinter.py? If so u should rename it, thats how I was able to solve the problem. Posts: 6,567 Threads: 116 Joined: Sep 2016 Reputation: Jun-30-2020, 02:48 PM
No need to use jdos
Posts: 14 Threads: 4 Joined: Jun 2020 Reputation: Jun-30-2020, 02:48 PM First why don’t you install v3.8? Second, if you have problems with the path, uninstall all versions, reboot, install new version. When you start the installer be sure to check the auto path install. After that locate your python (usually C:UsersuserAppDataLocalProgramsPythonPython38-32Scripts) start cmd as administrator, cd to that folder and then run ‘pip install tkinter’ and all the other modules and libraries that you need. And always remember, Capitalization matters. Tkinter is not tkinter for v3. ‘label’ is not ‘Label’ and tk.tk() is not tk.Tk(), that is to help you out of trouble. If you need help with the commands check TkDocs. Cheers! Posts: 11 Threads: 4 Joined: Jun 2020 Reputation:
Thank you all, I |
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Problem with pymodbus — ModuleNotFoundError: No module named ‘pymodbus.client.sync’ | stsxbel | 1 | 2,127 |
Dec-05-2022, 03:26 PM Last Post: snippsat |
|
ModuleNotFoundError: No module named ‘omsdk.sdkproto’ | donvito7 | 4 | 418 |
Oct-20-2022, 02:56 PM Last Post: deanhystad |
|
[SOLVED] Tkinter module not found | Milan | 7 | 1,136 |
Aug-05-2022, 09:45 PM Last Post: woooee |
|
ModuleNotFoundError: No module named ‘_struct’ when starting pip3 | yuhuihu | 0 | 1,321 |
May-05-2022, 04:41 AM Last Post: yuhuihu |
|
ModuleNotFoundError: No module named ‘com’ | aleksg | 10 | 6,870 |
Apr-03-2022, 11:46 PM Last Post: jocktmpltmea |
|
ImportError: No module named PIL | rudeoil18 | 9 | 4,116 |
Mar-03-2022, 01:25 PM Last Post: snippsat |
|
Error: «ModuleNotFoundError: No module named ‘RPi'» | LucaCodes | 4 | 2,881 |
Dec-29-2021, 01:58 PM Last Post: LucaCodes |
|
«ModuleNotFoundError: No module named ‘PyQt5.QtWidgets’; ‘PyQt5’ is not a package» | chipx | 3 | 3,216 |
Dec-09-2021, 07:05 AM Last Post: chipx |
|
‘no module named’ when creating packages | mbastida | 4 | 2,389 |
Nov-30-2021, 10:43 AM Last Post: Gribouillis |
|
No module named ‘_cffi_backend’ error with executable not with python script | stephanh | 2 | 3,406 |
Nov-25-2021, 06:52 AM Last Post: stephanh |
- the
ImportError: No module named _tkinter, please install the python-tk package
in Python - Fix the
ImportError: No module named _tkinter, please install the python-tk package
in Python
This article will discuss the ImportError: No module named _tkinter, please install the python-tk package
error in Python and how to fix it.
the ImportError: No module named _tkinter, please install the python-tk package
in Python
Tkinter packages must be installed externally through the CLI
and imported to your program. Otherwise, you will encounter the ImportError: No module named _tkinter, please install the python-tk package
.
Let’s see the example.
Code:
Output:
ImportError: No module named _tkinter, please install the python-tk package
# or
ImportError: No module named _tkinter
Fix the ImportError: No module named _tkinter, please install the python-tk package
in Python
To fix the error, install the tkinter
package externally from the command line interface and then import it into the current program.
There might be a different version of the command based on your operating system (OS), so you can try the one that perfectly matches your OS.
If you have Python 3x then you need to run the following command. This command also works with Ubuntu.
sudo apt-get install python3-tk
Command — Fedora:
sudo dnf install python3-tkinter
Command — Arch Linux:
sudo pacman -S tk
Command — Debian-based and Python 3x:
sudo apt-get install python-tk
Moreover, if you are using RHEL, CentOS, or Oracle Linux, then you can use yum
to install tkinter.
yum install tkinter
Based on your OS, you should install the version that suits your system, then import the tkinter into your current program, and it should work fine.
Let’s try a basic GUI application with tkinter.
Code:
from tkinter import *
window=Tk()
# label
lbl=Label(window, text="Welcome to DelfStack.com", fg='blue', font=("Helvetica", 14))
lbl.place(x=60, y=100)
# title
window.title('DelfStack')
# size of the dialog box
window.geometry("400x200+10+10")
window.mainloop()
Output:
The above code will create a small dialog box, which in this case displays a label "Welcome to DelfStack.com"
and a title "DelfStack"
, but you can add more weights to it accordingly.