100
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?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Jim Syyap
  • 1,625
  • 7
  • 20
  • 23

14 Answers14

327

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.

bdoubleu
  • 19
  • 5
Pinna_be
  • 4,517
  • 2
  • 18
  • 34
  • 8
    This package was indeed needed for me, but keep in mind that the name of `Tkinter` is now `tkinter` in Python3, so other answers are still relevant. – Luke Marlin Mar 02 '15 at 18:17
  • first command I get connection failed, the second one works fine though – Lost Crotchet Aug 27 '18 at 11:54
  • 1
    I don't know what happened, `sudo apt-get install python3-tk` did not work for me (tkinter still not found), but installing `python3-tk` via synaptic did work. (Ubuntu 16.04 with python 3.6) – Georg Nov 25 '18 at 14:22
  • It still works. Well done – Dominiksr Jun 11 '22 at 09:59
  • 1
    Perhaps quite late, but I checked the output of ``apt-cache policy python3*-tk`` , it gave me `python3-tk` as the viable one, the entries for 3.10-tk and 3.11-tk were blank. Installing `python3-tk` worked for me. (Ubuntu22.04, Python 3.10.6) – Luce Jan 26 '23 at 02:30
39

The answer to your question is that Tkinter is renamed to tkinter in python3.

That is with lowercase t.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Nils Nyman
  • 399
  • 2
  • 2
  • This is the actually correct answer based on what is actually shown in the original question. Everything else is making assumptions and solving a common problem, but not engaging with the issue actually shown in OP's actual attempt. – Karl Knechtel Apr 25 '23 at 18:15
20

In python 3 Tkinter renamed tkinter

user2569010
  • 201
  • 2
  • 2
  • This is the answer to the question. PS: If you run your script with a shebang, don't forget to use "#!/usr/bin/python3". On Ubuntu 12.04 for example default version of Python is 2.7.3 so "Tkinter" will work with "#!/usr/bin/python" but not with Python 3. – rbaleksandar Sep 28 '13 at 12:43
  • Second that this is the best and simplest answer to the question – Hamman Samuel Jun 15 '15 at 17:41
17

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
galoget
  • 722
  • 9
  • 15
Kishan Kishore
  • 451
  • 6
  • 12
14
sudo apt-get install python3-tk
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Roberto Júnior
  • 149
  • 1
  • 3
11

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.

onteria_
  • 68,181
  • 7
  • 71
  • 64
  • 22
    "sudo apt-get install python-support" leads to the following error "E: Package 'python-support' has no installation candidate" – jason Dec 09 '16 at 01:04
  • 6
    I also had the same error as @jason `E: Package 'python-support' has no installation candidate` though I am running it from a docker (tensorflow image). Did anyone know how to fix it? – Charlie Parker Apr 03 '17 at 21:09
  • 18
    @CharlieParker On Ubuntu 16.04 LTS, I was able to fix this by `apt-get install python3-tk` – rohitmohta Dec 03 '17 at 19:44
  • For those of you with the `E: Package 'X' has no installation candidate`, you should run `sudo apt-get update` first. – Daniel Patrick Aug 01 '18 at 10:01
  • is there a way I can do this in a gitpod too? it doesnt let me use sudo nor lets me do without it – Aakanksha Choudhary Feb 07 '21 at 06:24
  • @AakankshaChoudhary You ___hav___ to use sudo for this, it's not possible without – TheEagle Apr 06 '21 at 22:19
9

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
TheTechRobo the Nerd
  • 1,249
  • 15
  • 28
abhimanyu singh
  • 103
  • 1
  • 7
5

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.

Mohit Sinha
  • 61
  • 1
  • 4
4

this works for me:

from tkinter import *
root = Tk()
l = Label(root, text="Does it work")
l.pack()
user1497423
  • 707
  • 7
  • 3
2

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
parsethis
  • 7,998
  • 3
  • 29
  • 31
2

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.

l Steveo l
  • 516
  • 3
  • 11
1

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
galoget
  • 722
  • 9
  • 15
MaNKuR
  • 2,578
  • 1
  • 19
  • 31
0

requirement for tkinter:

python 3.6+

and go to shell write the test code like :

from tkinter import *

root = Tk()

root.mainloop()

enter image description here

Sarvesh
  • 95
  • 1
  • 13
-1

For Ubuntu 20.04 this works for me.

sudo apt-get install python3.6-tk
IS_Eagle_NG
  • 21
  • 1
  • 7