Tkinter: Python in-built Graphical User Interface (GUI)

Amit Chauhan
3 min readJul 10, 2022

Creating GUI-based application with python examples

Photo by Taras Shypka on Unsplash

Graphical user interfaces in everywhere in our technology, where we interact with the function of electronic devices through touch buttons, input box, audio, visual information, etc.

Introduction

The Tkinter is python’s in-built library to make basic to advance graphical user interface applications. There are many elements in the Tkinter to create GUI and these elements are buttons, entry fields, text, menu, scrollbar, etc.

Example 1

Let’s see the basic example of creating a simple button GUI with python.

#importing all the class methods from the Tkinter
from tkinter import *
#First we need to create a root window, where all these elements can
#can be used upon
root = Tk()

The Tk() is a instance that helps and manages the root window and its elements.

#frame is a space where we use our elements to be place
frame = Frame(root)
#It used to manage of placing elements in the frame
frame.pack()
#creating button inside the frame
button = Button(frame, text ='Hello World')
button.pack()

There are many parameters in the button, let’s know these two for now to understand the working. The first parameter frame represents the parent window i.e. we created the frame before the button. The second parameter text is used to give the name of the button.

#event loop of mainloop
root.mainloop()

This mainloop method is used to execute the application of tkinter and run forever until the user closes the window.

Output:

Example 2

We can use geometry to set the opening window size and set the title of the page with the title method as shown below example.

#importing all the class methods from the Tkinter…