What is Tkinter used for and how to install this Python Framework?

what is tkinter used for

Tkinter is the de facto way in Python to create Graphical User interfaces (GUIs) and is included in all standard Python Distributions. In fact, it’s the only framework built into the Python standard library. 

This Python framework provides an interface to the Tk toolkit and works as a thin object-oriented layer on top of Tk. The Tk toolkit is a cross-platform collection of  ‘graphical control elements’, aka widgets, for building application interfaces.

If you want to take advantage of the latest version of Tkinter, you’ll need to install a version of Python that supports Tcl/Tk 8.5 or greater. This will provide you with the Ttk (Tile extension integrated into Tk), which is required in order to run the current Tk widget set. 

Warning: If you’re working on a system that comes with Python pre-installed, you may need to upgrade it to at least Python 3.7, which includes everything you need to run Tk out of the box.

To verify the Tcl version on your computer, enter:

$ tclsh
% info patchlevel
    8.6.8

To open a Tcl/Tk shell and verify that it is working, enter a command similar to the following:

On a Linux system:

$ /opt/<tcl_version>/bin/wish8.6 

On a Windows system:

C:\Tcl\bin\wish86

A popup window titled wish8.6 will appear.

To verify that Tkinter is properly installed, enter:

$ python -m tkinter 

A popup window that states the Tcl/tk version should appear. 

What is Tkinter Used For 

This framework provides Python users with a simple way to create GUI elements using the widgets found in the Tk toolkit. Tk widgets can be used to construct buttons, menus, data fields, etc. in a Python application. Once created, these graphical elements can be associated with or interact with features, functionality, methods, data or even other widgets. 

For example, a button widget can accept mouse clicks, and can also be programmed to perform some kind of action, such as exiting the application.

How to Use Tkinter

In the following example, Tkinter creates a Tk application frame and a button widget that exits the application when clicked.

from tkinter import *
tk = Tk()
frame = Frame(tk, borderwidth=2)
frame.pack(fill=BOTH, expand=1)
label = Label(frame, text="Button Example")
label.pack(fill=X, expand=1)
button = Button(frame, text="Exit", command=tk.destroy)
button.pack(side=BOTTOM)
tk.mainloop()

How to Download Tkinter for Python 3

As previously stated, the best way to get the latest version of Tkinter is to install Python 3.7 or later. But Tkinter can also be downloaded and installed as part of any standard Python 3 installation.

How to Install Tkinter 

If you are using a Python 3 version prior to Python 3.7, or a non-standard version of Python 3 that does not include Tkinter, do the following:

On a Linux System:

$ sudo apt-get install python3-tk

On a Windows or Mac System:

The simplest and easiest method to install Tkinter, is to either:

Learn more about installing and verifying Tkinter on Windows here.

Frequently Asked Questions
Where can I find a Tkinter download?

Tkinter is not available as a standalone package for download. Instead, it is included in the standard library of recent versions of Tcl and Python. The easiest way to download Tkinter is therefore to install a recent version of Tcl or Python.

Download ActivePython, which includes the latest version of Tkinter. Or download ActiveTcl, which includes the latest version of Tkinter.

How do I install Tkinter on Windows?

The only way to install Tkinter on Windows is to install either Tcl 8.5 or later, or else install Python 3.7 or later. Both Tcl and Python contain Tkinter as a standard library.

Download ActivePython, which includes the latest version of Tkinter. Or download ActiveTcl, which includes the latest version of Tkinter.

Learn more about how to install Tkinter on Windows.

How do I download Tkinter for Python?

Tkinter for Python is not available as a standalone package for download. Instead, it is included in the standard library of recent versions of Python. The easiest way to download Tkinter is therefore to install a recent version of Python.

Download ActivePython, which includes the latest version of Tkinter.

Which Tkinter version should I download?

Older versions of Tkinter do not include the latest widgets provided by the Ttk extension. The best Tkinter download version is 8.5 or later, which includes Ttk. For Python developers, the easiest way to get the latest version of Tkinter is to install Python 3.7 or later.

Download ActivePython, which includes the latest version of Tkinter.

Recent Posts

Scroll to Top