user3791889
user3791889

Reputation: 51

How to install Tkinter?

How the hell to install tkinter on to my PC ?
I tried for week to install it. I can not figure it out. Please, Help.
How does it work ? Is there a site you install it from or what ?

Upvotes: 4

Views: 12825

Answers (4)

Lorem Ipsum
Lorem Ipsum

Reputation: 4524

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 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 tkinter

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

Upvotes: 4

MrMartin
MrMartin

Reputation: 467

Just change your code to

from tkinter import *

In python3, the issue is with capitalization, so you should use tkinter instead of Tkinter.

Upvotes: 0

gon1332
gon1332

Reputation: 2090

For Linux with aptitude:

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

sudo apt-get update
sudo apt-get install python3-tk

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

Upvotes: 3

Byron Coetsee
Byron Coetsee

Reputation: 3593

Should be there already man...

from Tkinter import *

Upvotes: 6

Related Questions