The Wayback Machine - https://web.archive.org/web/20241127025648/https://www.geeksforgeeks.org/what-are-widgets-in-tkinter/
Open In App

What are Widgets in Tkinter?

Last Updated : 26 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Tkinter is Python’s standard GUI (Graphical User Interface) package. tkinter we can use to build out interfaces – such as buttons, menus, interfaces, and various kind of entry fields and display areas. We call these elements Widgets.

What are Widgets in Tkinter?

In Tkinter, a widget is essentially a graphical component that the user can interact with. They can range from simple elements like buttons and labels to more complex ones like text entry fields, listboxes, and canvases. Each widget serves a specific purpose and can be customized to fit the design and functionality requirements of your application.

How Do Tkinter Widgets Work?

Each widget in Tkinter is an instance of a specific class defined in the Tkinter Module. These classes provide methods and attributes that allow you to configure the widget’s appearance, behavior, and functionality. Widgets are typically added to the application’s window or frames using layout managers like pack(), grid(), or place(), which determine their position and size within the interface.

Example: 

Python
from tkinter import *

# create root window
root = Tk()

# frame inside root window
frame = Frame(root)

# geometry method
frame.pack()

# button inside frame which is
# inside root
button = Button(frame, text='Geek')
button.pack()

# Tkinter event loop
root.mainloop()

Output : 

Tkinter Widget Basics

Tkinter supports the below mentioned core widgets – 

LabelDisplay static text or images.
ButtonIt is used to add buttons to your application
EntryIt is used to input single line text entry from user
FrameIt is used as container to hold and organize the widgets
RadioButtonIt is used to implement one-of-many selection as it allows only one option to be selected
CheckbuttonCreate checkboxes for boolean options.
ListBoxDisplay a list of items for selection.
ScrollbarAdd scrollbars to widgets like Listbox.
MenuIt is used to create all kinds of menu used by an application
CanvasDraw shapes, lines, text, and images.

Tkinter Widget Intermidate

WidgetsDescription
TextCreate a multiline text input with advanced editing capabilities.
ComboBoxProvide a dropdown list with editable text entry.
ScaleCreate a scale widget for selecting values within a range.
TopLevelCreate additional windows/dialogs.
MessageDisplay simple messages or notifications.
MenuButtonCreate a button that opens a menu.
ProgressBarShow progress of a task.
SpinBoxProvide a numerical input with up/down arrows.

Tkinter Widget Advance

WidgetsDescription
ScrolledTextCreate a text widget with built-in scrollbars.
TreeviewDisplay hierarchical data in a tree-like structure.
MessageBoxDisplay dialog boxes for messages, warnings, etc.
Treeview ScrollbarAdd scrollbars to Treeview widgets.

Geometry Management

Creating a new widget doesn’t mean that it will appear on the screen. To display it, we need to call a special method: either grid, pack(example above), or place. 

MethodDescription
pack()The Pack geometry manager packs widgets in rows or columns.
grid()The Grid geometry manager puts the widgets in a 2-dimensional table. 
The master widget is split into a number of rows and columns, and each “cell” in the resulting table can hold a widget.
place()The Place geometry manager is the simplest of the three general geometry managers provided in Tkinter. 
It allows you explicitly set the position and size of a window, either in absolute terms, or relative to another window.

 


Similar Reads

Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Python Tkinter | Create LabelFrame and add widgets to it
Tkinter is a Python module which is used to create GUI (Graphical User Interface) applications. It is a widely used module which comes along with the Python. It consists of various types of widgets which can be used to make GUI more user-friendly and attractive as well as functionality can be increased. LabelFrame can be created as follows: -> i
2 min read
Remove Widgets from grid in Tkinter
Do you know that you can remove or display the widgets from a grid on a single button click while working in your app? We can remove widgets from the grid by declaring the function for remove with grid_remove() method for every widget and then call that function in the button. Similarly, for displaying the widgets back on screen, We can declare the
4 min read
Disable focus for tkinter widgets - Python
Prerequisite: Python-Tkinter In this article, we will discuss how to disable the focus from the widgets in the Tkinter framework. For disabling the focus, we use takefocus option inside the widget and assign its value to 0. Stepwise implementation: Step1: Import Tkinter and initialize tkinter window C/C++ Code # import tkinter import tkinter as tk
3 min read
How to Add a Scrollbar to a Group of Widgets in Tkinter
In Tkinter, creating graphical user interfaces (GUIs) often involves arranging multiple widgets within frames or canvases. However, when the number of widgets exceeds the visible area, users may struggle to access all content. To address this, integrating scrollbars allows users to navigate through the widget group seamlessly. This article elucidat
2 min read
How to Hide, Recover and Delete Tkinter Widgets?
Tkinter is a Python Package for creating GUI(Graphical User Interface) applications. Tkinter provides us with a variety of common GUI elements which we can use to build out interfaces — such as buttons, label, frame, message, menu, and various kind of entry fields and display areas. We call these elements of Widgets. Widget is an element of Graphic
3 min read
Python | Multiple Sliders widgets Controlling Background Screen or WindowColor in Kivy
Prerequisite - Slider in KivyKivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.In this article, we will learn How we can control the background color in kivy that me
3 min read
How to use multiple UX Widgets in kivy | Python
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. ???????? Kivy Tutorial - Learn Kivy with Examples. UX Widgets: Classical user interface widgets, ready to be assem
3 min read
Django form field custom widgets
A widget is Django’s representation of an HTML input element. The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget. Whenever you specify a field on a form, Django will use a default widget that is appropriate to the type of data that is to be displayed. To find which widg
3 min read
Creating Custom Widgets in PyQt5
PyQt5 is one of the most advanced GUI library for Python. While being powerful, it's also well structured and makes it easy for you to build 'advanced' items. Custom widgets in PyQt5 is a breeze. The below has a well-described way of building custom Widgets with PyQt5, The Main Window Let's start by creating our main window. We go the OOP route rig
2 min read
PyQt5 QDockWidget – Setting Multiple Widgets Inside it
In this article we will see how we add/set multiple widgets to the QDockWidget. QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow(original window). We use setWidget method to add/set widget to t
2 min read
PyQtGraph – Adding Qt Widgets with the Bar Graph
In this article we will see how we can add Qt widgets with the bar graph in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and
3 min read
Matplotlib - Textbox Widgets
In this article, we are going to see matplotlib's textbox widget. Matplotlib is a plotting library for the Python programming language. In this article, we will try to plot a graph for different powers(e.g. t^2, t^3, t^9, etc.) using textbox widget. The Textbox is a widget that accepts input from the user. Input can also be formulas so that we can
2 min read
Bokeh - Adding Widgets
Bokeh is a Python data visualization library for creating interactive charts & plots. It helps us in making beautiful graphs from simple plots to dashboards. Using this library, we can create javascript-generated visualization without writing any scripts. What is a widget? Widgets are interactive controls that we can use with bokeh applications
11 min read
How to line up different widgets horizontally in Bokeh?
Bokeh is a data visualization library that can be used to create beautiful graphics, from simple plots to complex dashboards with streaming datasets. Bokeh provides interactive plots in modern web browsers like Google Chrome etc, using HTML and JavaScript to present clean and highly interactive charts and plots. Bokeh allows us to create JavaScript
3 min read
Python | askopenfile() function in Tkinter
While working with GUI one may need to open files and read data from it or may require to write data in that particular file. One can achieve this with the help of open() function (python built-in) but one may not be able to select any required file unless provides a path to that particular file in code. With the help of GUI, you may not require to
2 min read
Python | Binding function in Tkinter
Tkinter is a GUI (Graphical User Interface) module that is widely used in desktop applications. It comes along with the Python, but you can also install it externally with the help of pip command. It provides a variety of Widget classes and functions with the help of which one can make our GUI more attractive and user-friendly in terms of both look
3 min read
Make Notepad using Tkinter
Let's see how to create a simple notepad in Python using Tkinter. This notepad GUI will consist of various menu like file and edit, using which all functionalities like saving the file, opening a file, editing, cut and paste can be done. Now for creating this notepad, Python 3 and Tkinter should already be installed in your system. You can download
6 min read
Facts App Using Tkinter module
This is an app that will provide us with Facts. With Python, we can make things very easy. We have a very amazing library so that we can do it. We just need two of the libraries and if we just combine the concept, we will be able to make a new thing. We just have to use tkinter and randfacts to do this so. Module RequiredTkinter: The tkinter packag
2 min read
Color game using Tkinter in Python
TKinter is widely used for developing GUI applications. Along with applications, we can also use Tkinter GUI to develop games. Let's try to make a game using Tkinter. In this game player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds. Colors used in this
4 min read
Python | Message Encode-Decode using Tkinter
Prerequisite : Basics of TkinterPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Python pr
5 min read
Python - Tkinter askquestion Dialog
In Python, There Are Several Libraries for Graphical User Interface. Tkinter is one of them that is most useful. It is a standard interface. Tkinter is easy to use and provides several functions for building efficient applications. In Every Application, we need some Message to Display like "Do You Want To Close " or showing any warning or Something
4 min read
Simple registration form using Python Tkinter
Prerequisites: Tkinter Introduction, openpyxl module.Python provides the Tkinter toolkit to develop GUI applications. Now, it’s upto the imagination or necessity of developer, what he/she want to develop using this toolkit. Let's make a simple information form GUI application using Tkinter. In this application, User has to fill up the required info
5 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Python | Random Password Generator using Tkinter
With growing technology, everything has relied on data, and securing this data is the main concern. Passwords are meant to keep the data safe that we upload on the Internet. An easy password can be hacked easily and all personal information can be misused. In order to prevent such things and keep the data safe, it is necessary to keep our passwords
4 min read
How to visualize selection and insertion sort using Tkinter in Python?
In this article, we are going to create a GUI application that will make us visualize and understand two of the most popular sorting algorithms better, using Tkinter module. Those two sorting algorithms are selection sort and insertion sort. Selection sort and Insertion sort are the two most popular algorithms. Selection sort is a comparison-based
6 min read
Python | Real time currency converter using Tkinter
Prerequisites : Introduction to tkinter | Get the real time currency exchange ratePython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and
4 min read
Python | Real time weather detection using Tkinter
Prerequisites : Introduction to tkinter | Find current weather of any cityPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest
5 min read
Python | Simple FLAMES game using Tkinter
Prerequisites: Introduction to TkinterProgram to implement simple FLAMES game Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and e
5 min read
Practice Tags :
three90RightbarBannerImg