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 Linux.
This guide is also available for macOS. On Windows, Tkinter is installed by default with Python.
Install Tkinter on Ubuntu Using apt
In Ubuntu, you'll note that the Tkinter library isn't installed in the default distribution. We can install Tkinter either from the command line with the apt
command or via the Software Center. The package we are looking for 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 sources of software we are using in our Ubutu system. The second command downloads and installs Tkinter.
After the installation is finished, you can start a Python interactive session and import the tkinter
package as shown below:
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]>>> import tkinter as tk
Now that you've completed the installation in your Linux system, you can start creating Python GUI applications with Tkinter.
Never miss an update
Enjoyed this? Subscribe to get new updates straight in your Inbox.
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.