How to install Tkinter? How to install Tkinter? tkinter tkinter

How to install Tkinter?


Should be there already man...

from Tkinter import *


For Linux with aptitude:

If you're using Python 3 then you must install as follows (writing in a terminal):

sudo apt-get updatesudo apt-get install python3-tk

Tkinter for Python 2 (python-tk) is different from Python 3's (python3-tk).


I assume you're using Windows. If so...

Step 1. Ignore the people who say to import tkinter as tk or "It should already be there".

You're not the only person to have this problem despite apparently every post on the Internet telling you one of those two (utterly unproductive) statements. *deep breath*

Step 2. Understand what you're trying to do.

You're trying to do two things. The first is to install the Tk GUI toolkit, also known as Tcl/Tk. This is a collection of software that exists independently of Python which allows for GUI development. The second is to have Python interact with Tcl/Tk. This is done with the tkinter module which allows you to call Tcl/Tk using Python.

The Python installer, by default, installs Tcl/Tk along with tkinter. The tkinter module is part of the standard library. Because tkinter is not useful without Tcl/Tk also installed, someone, somewhere, at some time, decided it wasn't worth packaging tkinter separately. I don't know why.

Maybe you didn't install Tcl/Tk and tkinter when Python installed. Maybe you decided to use a different GUI framework. Maybe you thought "Why should I install something that I'll never use, along with an IDE I'll never use." Maybe you later found out that a third-party library like seaborn requires it... *deep breath*

Step 3. Figure out how you want to accomplish the two things you're trying to do.

You have two options:

Option 1. Install Tcl/Tk manually. Then maybe you can find some saint who has packaged tkinter for you. But maybe the versioning isn't correct. So you could compile it from source and/or learn a lot about how Python packaging works.

Option 2. Rerun the Python installer. Select "Modify". Make sure that the "tcl/tk and IDLE" checkbox is ticked and press "Next" a bunch.

Fix Python so that it has <code>tkinter</code>

If all else fails, burn everything down and start from scratch. But hopefully the second option works for you like it did for me. :)