water has asked for the wisdom of the Perl Monks concerning the following question:

Pardon the newbie question.

Using 'grid' in Tk, is there a way to specify via the grid itself that the grid border lines should be visible, or does one accomplish this via adding border to the grid components (eg the cells)?

If the later, what if the cells are of different sizes, and one desires a regular grid, like graph paper?

Thanks, all!

Replies are listed 'Best First'.
Re: TK newbie -- grid lines
by kvale (Monsignor) on Oct 09, 2004 at 21:21 UTC
    grid() is like pack() in that it is just a geometry manager - it only specifies positions of widgets, no decoration.

    To get a decoration, of could specify a Frame, with a border, at each grid location. Then put your non-square widgets inside the frame. You might be also able to specify a background picture of a grid for you top-level window; I haven't tried this in my own work. Alternatively, one could use a Canvas, draw a grid on it, then add widgets where you want.

    -Mark

Re: TK newbie -- grid lines
by qumsieh (Scribe) on Oct 10, 2004 at 02:28 UTC
    is there a way to specify via the grid itself that the grid border lines should be visible

    No.

    does one accomplish this via adding border to the grid components (eg the cells)?

    Correct. One way you can do that is to specify

    -relief => 'solid',
    when instantiating your widgets.

    what if the cells are of different sizes, and one desires a regular grid, like graph paper?

    You have to calculate the size yourself. You either specify a size that you know is big enough for everything, or you get the size or your largest widget. Something like this untested code:

    # after you instantiate all your widgets in $master. $master->update; my $maxHeight = (sort {$b <=> $a} map $_->reqheight => $master->gridSlaves)[0]; my $maxWidth = (sort {$b <=> $a} map $_->reqwidth => $master->gridSlaves)[0]; $master->gridColumnconfigure($_, -minsize => $maxWidth) for 0 .. ($master->gridSize)[0]; $master->gridRowconfigure ($_, -minsize => $maxHeight) for 0 .. ($master->gridSize)[1];
    HTH.