Python Tkinter Widgets
In this tutorial, we will cover an overview of Tkinter widgets in Python. Tkinter widgets are the functional units on any Tkinter-based GUI application.
When you use the Tkinter module in Python, the first step is to create a Window object.
Once you have the window object, you can start adding the Tkinter widgets to the window.
There are different readymade Tkinter widgets available that can be used directly for creating user interfaces.
There are various controls, such as buttons, labels, scrollbars, radio buttons, and text boxes used in a GUI application.
These little components or controls of the Graphical User Interface (GUI) are known as widgets in Tkinter.
These are 19 widgets available in the Python Tkinter module. Below we have all the widgets listed with a basic description:
|Name of Widget
||If you want to add a button in your application then the Button widget will be used. A button is clickable and the user can click the button widget to perform any action.
||To draw a complex layout and pictures (like graphics, text, etc.) the Canvas Widget can be used.
||If you want to display a number of options as checkboxes then the Checkbutton widget can be used. It allows you to select multiple options at a time.
||To display a single-line text field that accepts values from the user Entry widget can be used.
||In order to group and organize other widgets, the Frame widget can be used. Basically, it acts as a container that holds other widgets.
||To Provide a single-line caption to another widget Label widget can be used. It can contain images too.
||To provide a user with a list of options the Listbox widget can be used.
||To provide commands to the user Menu widget can be used. Basically, these commands are inside the Menu button. This widget mainly creates all kinds of Menus required in the application.
||The Menubutton widget is used to display the menu items to the user.
||The Message widget mainly displays a message box to the user. Basically, it is a multi-line text which is non-editable.
||If you want the number of options to be displayed as radio buttons then the Radiobutton widget can be used. You can select one at a time.
||Scale widget is mainly a graphical slider that allows you to select values from the scale.
||To scroll the window up and down the Scrollbar widget in Python can be used.
||The Text widget mainly provides a multi-line text field to the user where users enter or edit the text and it is different from Entry.
||The Toplevel widget is mainly used to provide us with a separate window container
||The SpinBox acts as an entry to the "Entry widget" in which value can be input just by selecting a fixed value of numbers.
||The PanedWindow is also a container widget that is mainly used to handle different panes. Panes arranged inside it can either be horizontal or vertical
||The LabelFrame widget is also a container widget used to mainly handle complex widgets.
||The MessageBox widget is mainly used to display messages in desktop applications.
Using all the above-mentioned Widgets, we can create amazing GUI applications.
Let's see a simple example where you will see some of these Tkinter widgets in action:
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello, Studytonight!")
entry = tk.Entry(root)
button = tk.Button(root, text="Click Me!")
So in this tutorial, we got a basic introduction to Trinket Widgets. In our upcoming tutorial pages, we will cover each widget in detail with their respective code examples.