- 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
How to change the width of a Frame dynamically in Tkinter?
The frame widget in Tkinter works like a container where we can place widgets and all the other GUI components. To change the frame width dynamically, we can use the configure() method and define the width property in it.
Example
In this example, we have created a button that is packed inside the main window and whenever we click the button, it will update the width of the frame.
# Import the required libraries 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") def update_width(): frame.config(width=100) # Create a frame frame=Frame(win, bg="skyblue3", width=700, height=250) frame.pack() # Add a button in the main window ttk.Button(win, text="Update", command=update_width).pack() win.mainloop()
Output
Run the above code to display a window that contains a frame widget and a button.
Click the "Update" button to update the width of the frame.
- Related Articles
- How to change the background color of a tkinter Canvas dynamically?
- How to Change Tkinter Frame Title?
- Dynamically change the widget background color in Tkinter
- How do I change the background of a Frame in Tkinter?
- How to set the min and max height or width of a Frame in Tkinter?
- How to change the font and size of buttons and frame in tkinter?
- How to Match Width of Text to Width of Dynamically Sized Image/Title?
- How to generate Tkinter Buttons dynamically?
- How To Dynamically Resize Button Text in Tkinter?
- How to get the width of the Tkinter widget?
- How to set the width of a Tkinter Entry widget in pixels?
- How to set the height/width of a Label widget in Tkinter?
- How to clear out a frame in the Tkinter?
- How to dynamically add/remove/update labels in a Tkinter window?
- How to add Label width in Tkinter?

Advertisements