Sticky news
Archive - Originally posted on "The Horse's Mouth" - 2005-09-15 07:21:42 - Graham Ellis
The pack geometry manager adds widgets to your window from either side, or from the top and bottom, one at a time - so they form a single row or column. The place geometry manager places widgets at a specific offset within the frame and is the least commonly used of the three by a long way. The grid geometry manager allows you to place whole rows and columns of components in a grid.
With the grid geometry manager, all the cells in a row have to be the same height and all the cells in a column have to be the same width. Otherwise it just wouldn't BE a grid. So how does Tk handle individual component size variation?
By default, each column is made as wide as the widest component in it, and each row is made as tall as the tallest component. Smaller components are then centred in their cells, with the space (padding) distributed equally around all four sides.
If you don't want the space evenly distributed, you can use the -sticky option on your grid command to stick the component to the various sides ...
N - Stick to the top (North)
S - Stick to the bottom (South)
E - Stick to the right (East)
W -Stisck to the left (West).
For example -sticky NW will place the widget in the top right corner of its cell.
To stretch a widget, you may specify that it's to stick to two opposite sides, and to stretch it to fill the cell you can stick it to all four sides - thus -sticky news