import tkinter as tk root = tk.Tk() frame = tk.Frame(root) frame.pack() # Add three labels to the frame tk.Label(frame, text="Column 1").grid(row=0, column=0) tk.Label(frame, text="Column 2").grid(row=0, column=1) tk.Label(frame, text="Column 3").grid(row=0, column=2) # Configure each column to have equal weight for i in range(3): frame.columnconfigure(i, weight=1) root.mainloop()
# Set the minimum width of column 2 to 100 pixels frame.columnconfigure(2, minsize=100)
# Add 20 pixels of padding to the left and right of column 1 frame.columnconfigure(1, pad=20)This code adds 20 pixels of padding to the left and right of column 1, which creates some extra space between its contents and the adjacent columns. In conclusion, columnconfigure is a very useful method in the Python Tkinter library that allows you to configure the properties of the columns in a Frame widget. Whether you want to set the width, minimum size, or padding of a column, columnconfigure makes it easy to do so in just a few lines of code.