How to Install Tkinter in Windows & Linux

In this article we want to learn How to Install Tkinter in Windows & Linux, so first of all let’s talk about TKinter.

 

 

What is TKinter ?

Tkinter is built in graphical user interface (GUI) library for Python programming language. It provides a way to create graphical user interfaces (GUIs) with Python, using the Tk GUI toolkit. Tkinter provides different set of widgets (e.g buttons, text boxes, etc.) and tools to create and manage windows, dialogs and other GUI elements. Tkinter is easy to use and widely used for creating desktop applications in Python.

 

 

How to Install Tkinter in Windows & Linux ?

Windows:

  • Tkinter is preinstalled in Python for Windows, no separate installation is required.
  • To check if Tkinter is installed, run the following command in the Python terminal: import tkinter
  • If there’s no error, Tkinter is installed.

Linux:

  • Tkinter is preinstalled in Python for Linux, no separate installation is required.
  • To check if Tkinter is installed, run the following command in the Python terminal: import tkinter
  • If there’s no error, Tkinter is installed.
  • If Tkinter is not installed, you can install it using the package manager of your Linux distribution. E.g., for Ubuntu, you can use the following command: sudo apt-get install python3-tk

 

 

Which Kind of GUI Apps I Can Make with TKinter ?

With Tkinter you can create different types of GUI based applications such as:

  • Desktop applications with a graphical user interface.
  • Multi Window applications.
  • Database driven applications.
  • Applications with simple dialogs and pop-up windows.
  • Applications with charts, graphs and images.
  • Custom widgets and controls for GUI.

Tkinter provides comprehensive set of GUI building blocks, making it a suitable tool for building simple to complex GUI applications.

 

 

This is an example of a simple Tkinter application that displays greeting message:

 

When you run the above code, it will create a window with label and button. when you click the button, the text of the label will change to “Hello, Tkinter!”.

 

 

This is the image result

How to Install Tkinter in Windows & Linux
How to Install Tkinter in Windows & Linux

 

 

Learn More on Python

 

 

 

This is an example of the same simple Tkinter application, but this time using Object Oriented Programming (OOP) approach:

This time we have defined Application class that inherits from tk.Frame. The __init__ method sets up the frame and creates the widgets. create_widgets method creates the label and button. The greet method changes the text of the label when the button is clicked. When you run this code, it will create the same window as before with label and button.

 

 

 

Leave a Comment