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:
Widgets | description |
---|---|
Label | Used to display text or images on the screen |
Button | Lets you add a button to your app |
Canvas | It is used to draw pictures and other layouts such as text, graphics, etc. |
ComboBox | It contains a down arrow to select from a list of available options |
CheckButton | It shows the user a number of options as a toggle button from which the user can choose as many options as they want. |
RadiButton | It is used to implement multiple selections as it only allows one option to be selected |
Entyr | A single line of text input for entering the user |
Frame | It is used as a container to house and organize small parts |
Message | It serves the same purpose as a tag and refers to multi-line and non-editable text |
Scale | It is used to provide a graphical slider that allows any value to be selected from that scale |
Scrollbar | Used to scroll down the content. It offers a sliding controller. |
SpinBox | It allows the user to choose from a given set of values |
Text | It allows users to edit multiple lines of text and format how they are displayed |
Menu | It 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.