- 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 "fill" and "expand" options for tkinter pack method
Tkinter Pack Manager acts based on using the extra space within the parent widget. While packing a widget, we can specify whether the widget should shrink or fill in the entire screen. In order to enable the widget to grow in the entire window, we can use the 'fill' property. It helps to fill the widget in the screen by adding “x” as horizontal, “y” as vertical or “BOTH”.
Whenever we use expand(boolean) property, then we are generally resizing the widget size to expand in its available space. It takes boolean values as true or false. When the expand property is true for the widget, it means we can enable the grow property. On the other hand, if the expand property is set to false, it means we will disable the grow property of widgets.
Example
#Import tkinter library from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the Geometry win.geometry("750x250") #Create a Labelwin= Tk() Label(win, text= "Hey! There",font=('Helvetica 25 bold'), background= "burlywood1").pack(fill=BOTH, expand=1,padx=20,pady=20) win.mainloop()
Output
Executing the above code snippet will display a full width text window.
Now, expand the screen a little bit to see the changes that the text adjusts its size in the entire window.