Before you start the Tkinter tutorial, you need a working installation on your system. This short tutorial provides the steps to install Tkinter on Ubuntu and other Debian-based Linux distributions.
This guide is also available for macOS. On Windows, Tkinter is installed by default with Python.
Install Tkinter on Ubuntu Using apt
In Ubuntu, Tkinter isn't included in the default Python installation. You can install Tkinter either from the command line with the apt package manager or via the Software Center. The package you need is python3-tk.
Best practices in Python recommend using virtual environments instead of installing packages directly into the system Python installation. The command shown below installs Tkinter in your system Python.
To install Tkinter from the command line, execute the following commands:
$ sudo apt update
$ sudo apt install python3-tk
The first command updates the package information from all configured software sources on your Ubuntu system. The second command downloads and installs the Tkinter package for Python 3.
This same approach works on other Debian-based distributions such as Linux Mint and Pop!_OS, since they also use the apt package manager.
Verify the Tkinter Installation
After the installation is finished, you can verify that Tkinter is correctly installed by starting a Python interactive session and importing the tkinter package:
>>> import tkinter as tk
If the import completes without errors, Tkinter is ready to use. You can also check the installed version:
>>> tk.TkVersion
Now that you've completed the Tkinter installation on your Linux system, you can start creating Python GUI applications with Tkinter.
Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.