Next / Previous / Contents

4.3. Configuring column and row sizes

Unless you take certain measures, the width of a grid column inside a given widget will be equal to the width of its widest cell, and the height of a grid row will be the height of its tallest cell. The sticky attribute on a widget controls only where it will be placed if it doesn't completely fill the cell.

If you want to override this automatic sizing of columns and rows, use these methods on the parent widget w that contains the grid layout:

w.columnconfigure(N, option=value, ...)

In the grid layout inside widget w, configure column N so that the given option has the given value. For options, see the table below.

w.rowconfigure(N, option=value, ...)

In the grid layout inside widget w, configure row N so that the given option has the given value. For options, see the table below.

Here are the options used for configuring column and row sizes.

Table 2. Column and row configuration options for the .grid() geometry manager

minsize The column or row's minimum size in pixels. If there is nothing in the given column or row, it will not appear, even if you use this option.
pad A number of pixels that will be added to the given column or row, over and above the largest cell in the column or row.
weight To make a column or row stretchable, use this option and supply a value that gives the relative weight of this column or row when distributing the extra space. For example, if a widget w contains a grid layout, these lines will distribute three-fourths of the extra space to the first column and one-fourth to the second column:
    w.columnconfigure(0, weight=3)
    w.columnconfigure(1, weight=1)
If this option is not used, the column or row will not stretch.