What is Tkinter and How to Install it (Windows, macOS, Linux)

How to Convert PNG to TIFF in Python?

Are you scrounging through the web looking for how to install Tkinter on your device? Well, you’re in luck! This simple guide shows step-by-step how to achieve this.

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!

 

 

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: 

  1. First, verify if python is installed on your system by opening the Command Prompt and entering python –version. 
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.

  1. 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.

pip help

install PIP for Python

 

  1. 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:
pip install tk

succesfully installed Tkinter on Windows

 

  1. 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.
import tk
tkinter._test()

installing Tkinter on Windows

 

Installing Tkinter on macOS

If you would like to install Tkinter on a macOS machine:

  1. First, verify if python is installed on your system by opening the Terminal and entering python3 –version. 
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.

  1. 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. 
pip3 --version

pip help

 

If pip is installed, the version will be displayed. Else, if you don’t have pip installed, learn how to do it here.

  1. 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.
pip install tk

 

  1. 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.
import tk

 

Installing Tkinter on Linux

  1. First, verify if python is installed on your system by opening the Linux Terminal and entering python3 –version. 
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.

  1. 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

 

  1. Then, enter your password if prompted and enter “y” to confirm the installation.
  2. 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.
import tk

 

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:

  1. Label
    • A label is a one-line widget used to display text or an image on the screen.
  1. Frame
    • A frame is a container widget used to group and organize widgets.
  1. Button
    • A button is a widget that may contain text and when clicked, performs an action.
  1. Entry
    • An entry is a one-line text field that is used to get input from the user. 
  1. Text
    • A text is a widget that allows users to input multi-line text. 
  1. Canvas
    • A canvas widget is used to draw in your GUI. You can create shapes, graphs, and more.
  1.  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!

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts
Total
0
Share