- How to Install Python Tkinter on Linux
- Prerequisites
- Install Tkinter in Linux
- Verify the Tkinter installation
- Running an Example with Tkinter
- What is Tkinter and How to Install it (Windows, macOS, Linux)
- What is Tkinter and Why Do You Need it?
- Installing Tkinter on Windows
- Installing Tkinter on macOS
- Installing Tkinter on Linux
- Overview of the Widgets Used to Create GUIs
- Conclusion
- Pip Install Tkinter
- Pre-requisites
- Python
- Pip
- Check for Built-in Tkinter Package
- Installing Tkinter with Pip
- Testing the Tkinter Package
- Conclusion
- About the author
- Abdul Mannan
How to Install Python Tkinter on Linux
Tkinter is a Python library that is used to create graphical user interfaces (GUIs). It is a standard Python interface to the Tk GUI toolkit, which is widely used in the Linux operating system. In this tutorial, we will learn how to install Tkinter on a Linux system using either pip or apt-get.
Prerequisites
To install Python’s Tkinter module on a Linux system, you will need to have the following prerequisites installed:
- Python: Tkinter is a module for Python, so you will need to have Python installed on your system. Most Linux distributions come with Python pre-installed, but if you don’t have it installed you can use your distribution’s package manager to install it.
- Tcl/Tk: Tkinter is built on top of the Tcl/Tk libraries, so you will need to have these libraries installed in order to use Tkinter. Most Linux distributions come with Tcl/Tk pre-installed, but if you don’t have them installed you can use your distribution’s package manager to install them.
- A development environment: In order to install Tkinter, you will need to have a development environment set up on your system. This typically includes a compiler (such as GCC) and the make utility. If you don’t have these tools installed, you can use your distribution package manager to install them.
Install Tkinter in Linux
Python Tkinter library packages are available under the default package repositories. You can install it using the system’s package manager to install the Python Tkinter module based on the operating system.
- On Debian-based Linux (Ubuntu, Debian, Pop!_OS):
sudo apt-get install python3-tk
sudo yum install -y tkinter tk-devel
sudo dnf install python3-tkinter
This will install the Tkinter module on your system.
Verify the Tkinter installation
Once the Python Tkinter module is successfully installed on your system. The following command will show you the Tkinter versions.
The below screenshot shows that Python Tkinter 8.6 is installed.
Running an Example with Tkinter
Let’s make a sample Python program using the Tkinter module. Create a file `example.py` file with the following content.
What is Tkinter and How to Install it (Windows, macOS, Linux)
Python has a wide array of frameworks that are used for building GUI (Graphical User Interface) applications. However, the only framework that is included in the Python standard library is Tkinter .
So, since Tkinter is already part of the standard Python library, it typically comes included with installations of Python. However, if you’re yet to install Python or your version of Python doesn’t include Tkinter, don’t worry!
In this guide, we’ll go over how to install Tkinter on Windows, macOS, Linux , and also the visual elements that are included in Tkinter.
So, let’s jump right into it!
Table of Contents
What is Tkinter and Why Do You Need it?
Tkinter is the de-facto Python framework for building GUI applications, and with good reason.
Tkinter is widely used due to the fact that it’s cross-platform , has a native look and feel , and provides a lot of customizability . Additionally, Tkinter has also been praised for being easily understandable thanks to its smaller library size .
While having many advantages, Tkinter also has disadvantages . So, Tkinter has been said to have a UI that isn’t always reliable and it also doesn’t include advanced widgets . However, many people would argue that the advantages outweigh the disadvantages.
Overall, Tkinter is useful for many different people and needs, including those who want to get a working and native-feeling application that runs on multiple operating systems quickly and efficiently.
Now, that we have a basic understanding of what it is, let’s jump right into the steps to install it!
Installing Tkinter on Windows
If you would like to install Tkinter on a Windows machine:
- First, verify if python is installed on your system by opening the Command Prompt and entering python –version .
If python is installed on your system, the version will be displayed. Else, if you don’t have python installed, you can install it from here.
- Next, verify if pip is installed on your system as we will be using pip to install Tkinter. So, enter pip help in the command line.
Again, if pip is installed, the version will be displayed. Else if you don’t have pip installed, you can learn how to install it here .
- Third, install Tkinter by entering pip install tk in the command line. Once Tkinter has been installed, you will receive a confirmation message that looks like the following:
- Lastly, enter import tk in the Python Terminal once Tkinter has been installed to verify if it works. There should be no error message shown once imported. You can also enter tkinter._test() after importing, and a small GUI window should appear that looks like this.
Installing Tkinter on macOS
If you would like to install Tkinter on a macOS machine:
- First, verify if python is installed on your system by opening the Terminal and entering python3 –version .
If python is installed on your system, the version will be displayed. Else, if you don’t have python installed, you can install it from here.
- Second, verify if pip is installed on your system as we will be using pip to install Tkinter. So, enter pip3 –version or pip help in the Terminal.
If pip is installed, the version will be displayed. Else, if you don’t have pip installed, learn how to do it here .
- Third, install Tkinter by entering pip install tk in the Terminal. You will receive a confirmation message that looks similar to the one listed in the Windows section once Tkinter has been installed.
- Lastly, enter import tk in the Python Terminal once Tkinter has been installed to verify if it works. There should be no error message shown once imported.
Installing Tkinter on Linux
- First, verify if python is installed on your system by opening the Linux Terminal and entering python3 –version .
If python is installed on your system, the version will be displayed. Else, if you don’t have python installed, you can install it from here.
- Second, assuming you are using a Debian-based distribution of Linux, install Tkinter by entering sudo apt-get install python-tk in the Linux Terminal.
sudo apt-get install python-tk
- Then, enter your password if prompted and enter “y” to confirm the installation.
- Lastly, enter import tk in the Python Terminal once Tkinter has been installed to verify if it works. There should be no error message shown once imported.
Overview of the Widgets Used to Create GUIs
Widgets are basic elements and they are essential to the creation of GUIs using Tkinter. Without widgets, users wouldn’t be able to interact with and use an application properly.
Therefore, below are a few examples of common widgets used in the Tkinter library:
- Label
-
- A label is a one-line widget used to display text or an image on the screen.
- Frame
-
- A frame is a container widget used to group and organize widgets.
- Button
-
- A button is a widget that may contain text and when clicked, performs an action.
- Entry
-
- An entry is a one-line text field that is used to get input from the user.
- Text
-
- A text is a widget that allows users to input multi-line text.
- Canvas
-
- A canvas widget is used to draw in your GUI. You can create shapes, graphs, and more.
- Checkbutton
-
- A checkbutton widget is a button that is used to execute an on/off choice. A checkbutton is commonly used for customization purposes where users can choose whether they want to turn a setting on or off.
Conclusion
Learning how to develop a GUI application can be a very beneficial skill to add to your skillset.
There are many reasons why someone may want to develop a GUI application. These range from wanting to add on to their programming skills to develop a user-friendly version of their project that previously ran on the command line. The latter can be very helpful when it comes to getting a non-computer savvy person to use an application as navigating through a GUI is far easier than the command line.
That being said, in this article, we looked at how to install Tkinter on Windows , macOS , and Linux machines and verifying that it works. Additionally, we looked at the basic building blocks of GUIs on Tkinter, called widgets .
Having said that, we hope you’ve found this guide helpful when it comes to installing Tkinter and understanding the basics of widgets.
Feel free to share this post with your fellow coders to guide them through installing Tkinter!
Pip Install Tkinter
The “Tkinter” package/library of python is used to develop the Graphical User Interfaces of python-based applications with great ease and control. What most people don’t realize is that the Tkinter package comes pre-installed in python 3.7 or higher, and if that is not the case, then it can be separately downloaded using the Pip commands.
Pre-requisites
There are a few pre-reqs for installing and using the Tkinter Package, and these pre-reqs include:
Python
Python must be installed in the user’s PC to not only install Tkinter but also to use it. To verify if python is installed on the PC or not, run the following command inside a Command Prompt or any other terminal:
The above command will produce the following results if python is installed:
Pip
After python, ensure that pip is also installed on the PC by using the following command inside the Command Prompt or any other terminal:
The output confirms that pip is installed on the user’s PC.
Check for Built-in Tkinter Package
As mentioned above, the Tkinter package also comes pre-installed with python 3.7 and higher. This essentially means that the user might not need to explicitly install the Tkinter package as it may already be installed on his machine. To verify this, run the following command inside the Command Prompt:
If the tkinter package is already installed, then the above command will result in the following output:
If the output is an error, then that means that the tkinter package is not pre-installed on your PC.
Installing Tkinter with Pip
Once you have made sure that you have all the prerequisites installed and also that there is no built-in tkinter with your python package, simply install the Tkinter using the following pip command:
Alternatively, you can also use the following command:
Both of the above commands will download and install the Tkinter package on your PC:
Testing the Tkinter Package
To test that the tkinter package has been successfully installed and is working, simply open up a python shell, by typing in “python” in a command prompt window:
After that, import the tkinter package and launch a new frame using the following lines:
After that, the following window will open up:
The window contains a demo GUI from the tkinter package, which contains two buttons, “Click me!” and “QUIT,” and two statements that display the version of the TK or the TCL package. The current version installed is the “Tcl 8.6”
Conclusion
The “pip install tkinter” command is used to install the tkinter package in python, a Graphical User Interface builder package that provides many features to the developer. However, this Tkinter package, also known as Tcl or TK package, comes as a built-in module with python 3.7 and higher. Therefore, the user might not necessarily need to install the tkinter package separately. This post has pictorially represented the purpose and the usage for the “pip install tkinter” command.
About the author
Abdul Mannan
I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor’s degree in computer science.