- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between "grid" and "pack" geometry managers in Tkinter
In order to view the widgets on the screen, we have to first associate each and every widget with the geometry manager. There are three ways in which we can view our widgets in the application. The Grid and Pack geometry manager are mostly used in many applications.
Pack Geometry Manager
The Pack geometry manager is one of the simplest geometry managers. We can use Pack manager to provide additional properties to the widgets such as padding, position respect to the X and Y axis, and expand property. It works on the basis of single row and single column. All the properties of Pack manager are applicable to all the widgets in Tkinter Library.
Grid Geometry Manager
Often, the Grid geometry manager is used for complex application development. It is manly used where we need to arrange many widgets inside a window such that they don't interfere with each other. Grid geometry manager works similar to the basic coordinate geometry system. It provides a layout feature to all the widget where we can place the widget in X and Y directionally. It works on the basis of multiple rows and multiple columns.
Example
# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win= Tk() # Set the size of the window win.geometry("700x350") # Add Label and Button widgets Button(win, text= "Button-1").grid(row=0, column=1, padx= 10, pady=20) # Button(win, text= "Button-2").pack(padx= 10, pady=20) win.mainloop()
Output
Now, uncomment the Button-2 widget and comment out the Button-1 widget to see the resultant output.
- Related Articles
- Difference between .pack and .configure for widgets in Tkinter
- What is a better Tkinter geometry manager than .grid()?
- When and how to use pack or grid layouts in tkinter?
- Difference Between Electron Geometry and Molecular Geometry
- Difference between "fill" and "expand" options for tkinter pack method
- Python - geometry method in Tkinter
- Difference between Conventional Grid and Smart Grid
- Difference between tkinter and Tkinter
- Difference between CSS Grid and Bootstrap
- Difference between Cluster Computing and Grid Computing
- Difference between Cloud Computing and Grid Computing
- Difference between import tkinter as tk and from tkinter import
- How to add space between two widgets placed in a grid in tkinter?
- Difference between title() and wm_title() methods in Tkinter class
- Creating a tkinter GUI layout using frames and grid
