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.


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

# Set the size of the window

def update_width():

# Create a frame
frame=Frame(win, bg="skyblue3", width=700, height=250)

# Add a button in the main window
ttk.Button(win, text="Update", command=update_width).pack()



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.