- 论坛徽章:
- 16
|
Handling Resize
If you've taken a peek below and added the extra "sticky" options to our example, when you try it out you'll notice things still don't look quite right (the entry is lower on the screen then we'd want), and things are even worse if you try to resize the window — nothing moves at all!
It looks like "sticky" may tell Tk how to react if the cell's row or column does resize, but doesn't actually say that the row or columns should resize if extra room becomes available. Let's fix that.
Every column and row has a "weight" grid option associated with it, which tells it how much it should grow if there is extra room in the master to fill. By default, the weight of each column or row is 0, meaning don't expand to fill space.
For the user interface to resize then, we'll need to give a positive weight to the columns we'd like to expand. This is done using the "columnconfigure" and "rowconfigure" methods of grid. If two columns have the same weight, they'll expand at the same rate; if one has a weight of 1, another of 3, the latter one will expand three pixels for every one pixel added to the first.
Both "columnconfigure" and "rowconfigure" also take a "minsize" grid option, which specifies a minimum size which you really don't want the column or row to shrink beyond.
More information refer to http://www.tkdocs.com/tutorial/grid.html#colsrows |
|