Tkinter Module
Tkinter Module
Python provides the standard library Tkinter for creating the graphical user interface for
desktop based applications.
An empty Tkinter top-level window can be created by using the following steps.
Example
from tkinter import *
#creating the application main window.
top = Tk()
#Entering the event main loop
top.mainloop()
Tkinter widgets
There are various widgets like button, canvas, checkbutton, entry, etc. that are used to build
the python GUI applications.
The Tkinter geometry specifies the method by using which, the widgets are represented on
display. The python Tkinter provides the following geometry methods.
1. The pack(): The Pack geometry manager packs widgets in rows or columns.
2. The 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.
3. The place() : It allows you explicitly set the position and size of a window,
either in absolute terms, or relative to another window.
pack() method
The pack() widget is used to organize widget in the block.
The widgets positions can be controlled by using the various options specified in the
method call using the pack() method.
Syntax:
widget.pack(options)
Example1:
parent = Tk()
parent.mainloop()
OUTPUT:
Grid() Method:
The grid() geometry manager organizes the widgets in the tabular form.
We can specify the rows and columns as the options in the method call.
We can also specify the column span (width) or rowspan(height) of a widget.
Syntax
widget.grid(options)
Example:
parent = Tk()
parent.mainloop()
OUTPUT:
ab: 5,18,28,32,33,48,22-16,34,65