How to create equal-width grid columns with Tkinter?

To make a gridded layout have all columns have the same width, you’ve got to configure those columns to have the same weight and to be in the same uniform group. This configuration is associated with the master widget, not any of the contained widgets (because columns can contain many widgets, of course).

In standard Tk, this is done with:

# "fred" is just some arbitrary key; it means nothing other than to name the group
grid columnconfigure $master 0 -weight 1 -uniform fred

In Tkinter (note that uniform seems to be not documented in the docstring but it is exactly what you need):

# "fred" is just some arbitrary key; it means nothing other than to name the group
master.grid_columnconfigure(0, weight=1, uniform="fred")

Then repeat for the other column indices that you want to set things for. (As you can see, the code’s very similar in these two cases.)

Leave a Comment