Table of contents
1.
Introduction
2.
Why Tkinter?
3.
Tkinter package in Python
4.
Installation
5.
Creating a Tkinter App
6.
Tkinter Basic Methods and Widgets
6.1.
Example
7.
Advantages of Tkinter
8.
FAQs
9.
Key Takeaways
Last Updated: Aug 21, 2025

Tkinter in Python: A Complete Guide

Author Sanjana Yadav
0 upvote

Introduction

Although Python has many GUI frameworks, Tkinter is the only one included in the standard library. Tkinter provides several advantages. The code is cross-platform, working on Windows, Mac OS X, and Linux. Tkinter programs seem like they belong on the platform they're running on because visual components are produced using native operating system elements.

Why Tkinter?

Tkinter is often regarded as the de-facto Python GUI framework; however, it is not flawed. Tkinter-based GUIs have been criticized for looking antiquated. Tkinter may not be what you're searching for if you want a slick, contemporary interface.

On the other hand, Tkinter is a lightweight framework that is reasonably easy to use compared to other frameworks. This makes it an attractive alternative for creating GUI apps in Python, especially for projects where a current gloss isn't required, and the main goal is to construct something that works on several platforms quickly.

Tkinter package in Python

Tkinter is the most often used GUI technique out of all the options. It's a Python interface to Python's Tk GUI toolkit. Python and Tkinter are the fastest and most straightforward approach to constructing GUI apps. It's simple to create a GUI with tkinter.

Installation

Python must be installed before Tkinter can be installed. When we install Python, we get Tkinter as well. We must check the td/tk and IDLE checkboxes while installing Python. We don't need to install Tkinter individually because this will do it for us.

If we forget to install Tkinter when we install Python, we may do it later with the pip command.

Make sure that Python and pip are already installed on your system using the below command:

python --version

The version of Python installed on your system will be displayed if python was successfully installed.

To check pip

pip -V

If pip has been successfully installed on your system, the version will be shown.

Install Tkinter

Pip may be used to install Tkinter. To install Tkinter, use the following command on the command prompt.

pip install tk

This command will begin downloading and installing Tkinter packages. After that, you'll get a message indicating successful installation.

Creating a Tkinter App

To create a Tkinter app:

  1. Import tkinter module.
    Importing tkinter is similar to importing any other Python package. The module's name in Python 2.x is 'Tkinter,' but in Python 3.x, it is 'tkinter.'
    import tkinter
     
  2. Create main window(container).
     
  3. Add as many widgets as you like to the main window.
     
  4. Apply event trigger on widgets.

Tkinter Basic Methods and Widgets

When building a Python application with GUI, there are two main methods that the user must know.

Tk(screenName=None,baseName=None,className=’Tk’,useTk=1): Tkinter provides the function Tk(screenName=None, baseName=None, className='Tk', useTk=1) for creating a main window. You may replace the className to the desired name to alter the window's name. The following is the basic code used to generate the application's primary window:
m=tkinter.Tk() where m is the name of the main window object

mainloop(): When your program is ready to run, you call the mainloop() function. mainloop() is an endless loop that runs the program, waits for an event, and processes the event as long as the window is open.

Example

import tkinter
m = tkinter.Tk()
'''
widgets are added here
'''
m.mainloop()
You can also try this code with Online Python Compiler
Run Code

Tkinter also provides access to the widgets' geometric configuration, which may be used to organize widgets in parent windows. There are three types of geometry manager classes.

  1. pack() method: arranges the widgets in blocks before placing them in the parent widget.
     
  2. grid() method: arranges the widgets in grids before placing them in the parent widget.
     
  3. place() method: Organizes the widgets by arranging them in the places specified by the programmer.

You may include a variety of widgets in your tkinter application. The Button, Canvas, CheckButton, Entry, Frame, Label, ListBox, MenuButton, Menu, Message, RadioButton, and Scale are some of the most important widgets.

Advantages of Tkinter

  • When compared to other GUI toolkits, Tkinter is the easiest and quickest to implement.
     
  • Tkinter is more adaptable and reliable.
     
  • Tkinter is included in Python; therefore, no other software is required.
     
  • Tkinter has a simple syntax.
     
  • Tkinter is extremely simple to learn and master.
     
  • Tkinter has three different geometry managers: put, pack, and grid. That is far more powerful and simple to use.
    Also see, How to Check Python Version in CMD

FAQs

  1. Can we use Tkinter for web development?
    The Tkinter package in Python is the quickest and easiest method to create an object-oriented GUI application. It gives us a selection of typical GUI (graphical user interface) elements such as buttons, menus, and other types of entry fields and display regions that we may utilize to design our user interface.
     
  2. Can we use HTML in tkinter?
    The tkhtmlview module is a set of Tkinter widgets whose text may be formatted in HTML. An HTML widget is not a web browser frame; rather, it is a basic and lightweight HTML parser that prepares the tags needed by the Tkinter Text base class.
     
  3. What is root tkinter?
    The root window is where all other widgets are placed. It is a Tk instance, and each tkinter application must contain precisely one instance of this class.app is a subclass of Frame and an instance of the class app.

Key Takeaways

Cheers if you reached here! With this, we have completed the Tkinter introduction, installed the Tkinter module, and even understand what Windows and Widgets are in Tkinter.

On the other hand, learning never ceases, and there is always more to learn.
Learn more about python modules and libraries with coding ninjas.
Check out the Python Interview Questions to get hands-on experience with frequently asked interview questions and land your dream job.
Good luck with your preparation!

Live masterclass