Introduction to Tkinter Development – Python GUI Development

Graphical user interface (GUI)

is a form of user interface that allows users to interact with a computer through visual indicators using icons, menus, windows, and other items. It has advantages over the Command Line Interface (CLI), where the user can interact with the computer simply by writing commands using the keyboard and its usage is more difficult than the GUI.

What is Tkinter?

Tkinter is a built-in python module for creating GUI applications. It is one of the most commonly used modules for creating GUI applications using Python because of its simplicity and ease of use. You don’t have to worry about the Tkinter module already installed separately, as it already ships with Python. It provides an object-oriented interface for the Tk GUI toolkit.

Some of the other Python libraries that can be used to create our own GUI applications are:

Kivy

Python Qt

wxPython

Of all Tkinters, they are the most widely used

What is a widget?

The elements in the GUI application in the widget Tkinter are elements of the GUI application that provide the user with various controls (such as labels, buttons, combo boxes, checkboxes, menu bars, radio buttons, etc.) to interact with the application.

The basic structure of the Tkinter program

Tkinter Basic Widgets:

Widgetsdescription
LabelUsed to display text or images on the screen
ButtonLets you add a button to your app
CanvasIt is used to draw pictures and other layouts such as text, graphics, etc.
ComboBoxIt contains a down arrow to select from a list of available options
CheckButtonIt shows the user a number of options as a toggle button from which the user can choose as many options as they want.
RadiButtonIt is used to implement multiple selections as it only allows one option to be selected
EntyrA single line of text input for entering the user
FrameIt is used as a container to house and organize small parts
MessageIt serves the same purpose as a tag and refers to multi-line and non-editable text
ScaleIt is used to provide a graphical slider that allows any value to be selected from that scale
ScrollbarUsed to scroll down the content. It offers a sliding controller.
SpinBoxIt allows the user to choose from a given set of values
TextIt allows users to edit multiple lines of text and format how they are displayed
MenuIt is used to create various menus used by the application

Example

from tkinter import * 
from tkinter.ttk import *
    
# writing code needs to
# create the main window of 
# the application creating 
# main window object named root
root = Tk()
  
# giving title to the main window
root.title( "First_Program" )
  
# Label is what output will be 
# show on the window
label = Label(root, text = "Hello World !" ).pack()
  
# calling mainloop method which is used
# when your application is ready to run
# and it tells the code to keep displaying 
root.mainloop()

The output is as follows

First, your interview preparation enhances your data structure concepts with the Python DS course.