Reputation: 1673
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
on the other hand...
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter
I checked synaptic, Tkinter is installed. Then I found this--
If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
I am guessing that tkinter is still associated with the old python in my pc. How do I change that so python3 can use tkinter?
Upvotes: 102
Views: 238043
Reputation: 61
For Ubuntu 22.04 this works for me.
sudo apt install python3-tk tk-dev
Upvotes: 0
Reputation: 21
For Ubuntu 20.04 this works for me.
sudo apt-get install python3.6-tk
Upvotes: -1
Reputation: 409
The answer to your question is that Tkinter
is renamed to tkinter
in python3.
That is with lowercase t.
Upvotes: 40
Reputation: 96
requirement for tkinter:
python 3.6+
and go to shell write the test code like :
from tkinter import *
root = Tk()
root.mainloop()
Upvotes: 0
Reputation: 103
If you are using Ubuntu 18.04 along with Python 3.6, then pip or pip3 won't help. You need to install tkinter
using following command:
sudo apt-get install python3-tk
Upvotes: 9
Reputation: 558
Adding solution for CentOs 7 (python 3.6.x)
yum install python36-tkinter
I had tried about every version possible, hopefully this helps out others.
Upvotes: 2
Reputation: 61
I had the same problem. I tried to use:
sudo apt-get install python3-tk
It gave an error stating blt(>=2.4z-7) is not present and is not installable.
I went here and manually installed it. (For Ubuntu 14.04)
Then I used apt again and it worked.
I concluded that python3.4 in Ubuntu didn't come with the .so file required to carry on installation. And blt was required to download it.
Upvotes: 5
Reputation: 2704
Adding the solution that I faced with python 3.4
on Fedora 21
. Hope this will help those facing a similar issue.
Any of these commands will install tkinter
:
sudo yum install python3-tkinter
OR
sudo dnf install python3-tkinter
Upvotes: 1
Reputation: 511
Use the following command:
sudo apt-get install python3-tk
The following commands do not work:
sudo apt-get install python3-tkinter
sudo apt-get install python3-Tkinter
pip3 install Tkinter
pip3 install tkinter
Upvotes: 20
Reputation: 4617
What worked for me in Ubuntu was actually just:
sudo apt-get install python3-tk
For python 3.6:
sudo apt-get install python3.6-tk
I didn't read anywhere, I simply tried it, as onteria_'s method didn't seem to work for me.
Upvotes: 330
Reputation: 8078
I found this looking for a fix for python 3.5.
In my case I was building python from source, here is what I did to help fix:
Add the tkinter headers with and rebuild python
sudo apt-get install tk8.6-dev
sudo make
Upvotes: 3
Reputation: 727
this works for me:
from tkinter import *
root = Tk()
l = Label(root, text="Does it work")
l.pack()
Upvotes: 4
Reputation: 70497
Since you mention synaptic I think you're on Ubuntu. You probably need to run update-python-modules to update your Tkinter module for Python 3.
EDIT: Running update-python-modules
First, make sure you have python-support
installed:
sudo apt-get install python-support
Then, run update-python-modules
with the -a
option to rebuild all the modules:
sudo update-python-modules -a
I cannot guarantee all your modules will build though, since there are some API changes between Python 2 and Python 3.
Upvotes: 11