Tkinter Canvas/Grid question

Jeff Epler jepler at unpythonic.net
Thu Sep 11 08:10:54 EDT 2003


To expand on Michael Peuser's response, I'll explain a little more.  The
grid first calculates the size requested by each item to find the
requested size for each row and column.  When there are no rowspans,
the requested size for a row is the maximum of the requested sizes for
any item in that row.  The same holds when talking about columns, their
weights and their widths.

Then, when there is too much or too little space, the difference is
split up among the rows according to their weight.  The default weight
for a row is 0.  Let total_weight be the sum of the weight of each row
with a widget, and diff be the number of pixels difference between the
height of the frame and the sum of the requested heights of its rows.  If
total_weight is 0, then all rows get their requested height.  Otherwise,
each row gets diff*row_weight/total_weight, with something done about
the rounding errors.

That's why the short answer to set the weight of row and column 0 to 1
works.

The other problem you may run into (I haven't run your code, but with
many levels of widget present, this may be a problem) is that each
level of the widget tree between this one containing the canvas, and the
Toplevel() or Tk() above it, must also be configured so that they will
expand to consume any extra available space.  Otherwise, the condition
"when there is too much or too little space" can't be true, because the
widget won't be given a larger size than it requested.

Jeff





More information about the Python-list mailing list