[ltk-user] Grid question

Peter Herth herth at peter-herth.de
Tue Aug 15 08:24:15 UTC 2006


Hi Bill,

sorry for a late (and a bit short) answer, but your mail caught me
during travel, but I will try what is possible in a short.

> I'm new to Ltk.   I seem to get it to work fine and have seen enough to
> want to really get familiar with it.  However, I have a few questions
> about the layout managers.   Basically, I want to be able to place
> things anywhere on the screen and have them stay relative to one another
> when the screen  is resized.
>
> When creating a grid, who owns it?    If I want a frame to be a grid of
> four by four and to place buttons at 1,0  and 2,3, how is that done?
> It seems that when I try this the first button goes to 0,0 and the
> second button to 1,1.
>
> Also, how do you create an empty frame of a specific size?    Or a nil
> (*tk*) window of a specific size?
>

In general, try to avoid grid rows/columns which are completely empty,
as they get shrunken to zero size. The grid layout is owned by the
container which owns it, that is either the toplevel window or the
frame whichin the grid is. (the master of the widgets you grid). The
sizing of the grid rows/columns is determined by the minimum size of
the widgets contained in the cells and by the weight  of the
row/column. You can adjust the weight by using grid-rowconfigure (or
grid-columnconfigure respectively) with the keyword :weight and a
parameter between 0 and 1, the heigher ones take more space when
resizing than the smaller ones.
But I personally use grid only when I really have to put things into a
grid, for most layouts I prefer the pack manager. The pack seems to be
quite restricted, you can only pack horizontally via :side :left (or
:right) or verticaly with :side :top (or :bottom). The magic trick is
to use frames to create containers for widgets packed in the other
direction. So in many applications I write, the top level pack goes
from the top to the bottom of the window, and whithin that I have
subframes which pack their contained widgets in a horizontal matter.
You can see an example for it in the ltktest program, which packs a
canvas on the top of the window and a frame at the bottom, which
contains a horizontal row of widgets. With pack you have to use the
:expand and :fill arguments to specify the resizing behaviour.
I hope this helps, don't heasitate to ask more :)

Peter



More information about the ltk-user mailing list