- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
# 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()
Now, uncomment the Button-2 widget and comment out the Button-1 widget to see the resultant output.
- 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?
- Python - geometry method in Tkinter
- Difference between tkinter and Tkinter
- Difference between "fill" and "expand" options for tkinter pack method
- Difference between Cluster Computing and Grid Computing
- Difference between Cloud Computing and Grid Computing
- Difference between import tkinter as tk and from tkinter import
- Difference between title() and wm_title() methods in Tkinter class
- Creating a tkinter GUI layout using frames and grid
- What is the difference between root.destroy() and root.quit() in Tkinter(Python)?
- What is the difference between focus and focus_set methods in Tkinter?
- How to add space between two widgets placed in a grid in tkinter?
- What is the difference between a variable and StringVar() of Tkinter?