- 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 .pack and .configure for widgets in Tkinter
We use various geometry managers to place the widgets on a tkinter window. The geometry manager tells the application where and how to organize the widgets in the window. With geometry manager, you can configure the size and coordinates of the widgets within the application window.
The pack() method in tkinter is one of the three geometry managers. The other geometry managers are grid() and place(). The pack() geometry manager is commonly used to provide padding and a way to arrange the widgets in the window.
To configure the properties and attributes of a widget explicitly after defining it, you can use the configure() method. The configure() method is also used to configure the widget properties including resizing and arrangement properties.
Example
In the following example, we have created a Label widget and Button widget. The properties and attributes of both the widgets can be configured efficiently using pack() and configure() methods.
# Import required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the window win.geometry("700x350") # Define a function def close_win(): win.destroy() # Create a label my_label=Label(win, text="Hey Everyone!", font=('Arial 14 bold')) my_label.pack(pady= 30) # Create a button button= Button(win, text="Close") button.pack() # Configure the label properties my_label.configure(bg="black", fg="white") button.configure(font= ('Monospace 14 bold'), command=close_win) win.mainloop()
Output
Running the above code will display a window with a Button and a Label widget. You can configure the properties of these widgets by manipulating the values in the configure() method.
- Related Articles
- Configure tkinter/ttk widgets with transparent backgrounds
- Difference between "fill" and "expand" options for tkinter pack method
- Difference between "grid" and "pack" geometry managers in Tkinter
- What is the difference between the widgets of tkinter and tkinter.ttk in Python?
- Showing and Hiding widgets in Tkinter?
- How to show and hide widgets in Tkinter?
- Changing the Default Font for all the widgets in Tkinter
- Difference between tkinter and Tkinter
- How to add space between two widgets placed in a grid in tkinter?
- How to create transparent widgets using Tkinter?
- How do you overlap widgets/frames in Python tkinter?
- How to capture events on Tkinter child widgets?
- How to delete Tkinter widgets from a window?
- Difference between import tkinter as tk and from tkinter import
- Adding a scrollbar to a group of widgets in Tkinter
