tkinter - How to stop frame changing size when widget is added? tkinter - How to stop frame changing size when widget is added? tkinter tkinter

tkinter - How to stop frame changing size when widget is added?


Grid accepts the parameter uniform, which takes an arbitrary value. All rows (or all columns) with the same value are considered to be part of a "uniform group". This forces the rows (or columns) to be a uniform size in proportion to their weight.

If you have two rows in a frame, both rows have an identical weight, and both belong to the same uniform group, they will each take up exactly 50% of the available space.

In your case you can do this:

innerFrame.grid_rowconfigure(0, weight=1, uniform="x")innerFrame.grid_rowconfigure(1, weight=1, uniform="x")

(again, the "x" is arbitrary; it can be any value as long as it's the same value for both rows)

The official documentation for tk (upon which tkinter is built) describes it like this (see http://tcl.tk/man/tcl8.5/TkCmd/grid.htm#M24)

The -uniform option, when a non-empty value is supplied, places the row in a uniform group with other rows that have the same value for -uniform. The space for rows belonging to a uniform group is allocated so that their sizes are always in strict proportion to their -weight values.

...

When multiple rows or columns belong to a uniform group, the space allocated to them is always in proportion to their weights. (A weight of zero is considered to be 1.) In other words, a row or column configured with -weight 1 -uniform a will have exactly the same size as any other row or column configured with -weight 1 -uniform a. A row or column configured with -weight 2 -uniform b will be exactly twice as large as one that is configured with -weight 1 -uniform b.


Note: the uniform option doesn't show up in the tkinter documentation, but it is a perfectly valid option. It has been a part of tk (upon which tkinter is built) for many, many years.


You can use a max-size, min-sixe to the frame:

master = tk()master.minsize(width=777, height=777)master.maxsize(width=777, height=777)