GUI (Graphical User Interface) is the common User Interface which is a visual representation of communication for the easy interaction between the machine and user. It includes buttons and icons for Graphical representation, and rather than the usual text-based or command-based communication it can be performed by interacting with these icons. Each and every GUI has its own features and functions.
Even without any prior computer knowledge one can perform the basic functions of a computer. Surprisingly, even for such a simple task GUI is responsible. GUI provides a visual representation of files present and provides details about it which makes searching very easy. Every response from the computer is visually communicated through GUI.
When designing the GUI of an application, it is important to decide what type of widgets are going to be used and how to organize those widgets in the application by using the specialized non-visible objects called layout managers in the Tkinter module.
Tkinter has three built-in layout managers:
Pack:
The pack geometry manager organizes widgets in horizontal and vertical boxes.
Code: # importing Tkinter module from tkinter import * # creating window object window = Tk() window.title("My First GUI Program") # window title window.minsize(width=300, height=300) # window size # creating Entry my_label = Label(text="I am a label", font=("Arial", 24, "bold")) my_label.pack() # creating Entry input = Entry(width=30) input.pack() # creating Button button = Button(text="Click Me") button.pack() window.mainloop() Output:![]()
Place:
The place geometry manager positions widgets using absolute positioning.
Code: # importing Tkinter module from tkinter import * # creating window object window = Tk() window.title("My First GUI Program") # window title window.minsize(width=300, height=300) # window size # creating Label my_label = Label(text="I am a label", font=("Arial", 24, "bold")) my_label.place(x=0, y=0) # position of Label # creating Entry input = Entry(width=30) input.place(x=100, y=100) # position of Entry # creating Button button = Button(text="Click Me") button.place(x=200, y=200) # position of Button window.mainloop() Output:![]()
Grid:
The grid geometry manager places widgets in a two dimensional grid.
Code: # importing Tkinter module from tkinter import * # creating window object window = Tk() window.title("My First GUI Program") # window title window.minsize(width=300, height=300) # window size # creating Label my_label = Label(text="I am a label", font=("Arial", 24, "bold")) my_label.grid(column=0, row=0) # position of Label # creating Entry input = Entry(width=30) input.grid(column=1, row=1) # position of Entry # creating Button button = Button(text="Click Me") button.grid(column=1, row=2) # position of Button window.mainloop() Output:![]()
Among all these built-in layout managers, I prefer the Grid because it makes designing and collaborating the design with other designers easier as they provide a plan for where to place elements.
Sajid Hussain Reply
Simple, clean and elegant with a proper and sound introduction.
Om Jaiswal Reply
Thank you, it is really great to hear that.