Ruby tk grid question

I have a frame defined within root and a TkLabel widget inside the
frame. I used pack to set the location of the frame within root and am
trying to use grid to set the location of the label in the frame. When
I set the grid loaction to column 1, row 1 it remains centered in the
page. I included "sticky => ‘w’ as an option to grid but it doesn’t
seem to work. The code I used is below. Any reason why column 1 is in
the middle of the page when it is resized?

root = TkRoot.new

top = TkFrame.new(root) {
background “white”;
pack(“side” => ‘top’, “fill” => ‘x’, “expand” => 1, “anchor” => ‘n’ )
}
date = TkFrame.new(top) {
background “white”;
pack(“side” => “top”, “fill” => ‘x’, “expand” => 1) }

TkLabel.new(date,“text”=>“Date:”).grid(“row” =>1,“column” =>1,“sticky”
=w’)

Tk.mainloop

From: Jon D. [email protected]
Subject: ruby tk grid question
Date: Thu, 25 May 2006 11:31:45 +0900
Message-ID: [email protected]

When
I set the grid loaction to column 1, row 1 it remains centered in the
page. I included "sticky => ‘w’ as an option to grid but it doesn’t
seem to work. The code I used is below. Any reason why column 1 is in
the middle of the page when it is resized?

Please read “THE GRID ALGORITHM” in the man of grid (man n grid).
You’ll have to set the proper values to ‘weight’ options of the
columns (e.g. date.grid_columnconfigure(1, :weight=>1) ).

Please read “THE GRID ALGORITHM” in the man of grid (man n grid).
You’ll have to set the proper values to ‘weight’ options of the
columns (e.g. date.grid_columnconfigure(1, :weight=>1) ).

Ok, that makes sense. I read through that quickly but didn’t make the
connection. I am not exactly sure what the master index is though. If
I have a frame(=top) within root and several frames within ‘top’, what
would the master index refer to? Thanks for the help.

From: Jon D. [email protected]
Subject: Re: ruby tk grid question
Date: Thu, 25 May 2006 17:32:09 +0900
Message-ID: [email protected]

Ok, that makes sense. I read through that quickly but didn’t make the
connection. I am not exactly sure what the master index is though. If
I have a frame(=top) within root and several frames within ‘top’, what
would the master index refer to? Thanks for the help.

Maybe, I’m misunderstanding your question.
First of all, the followings are same.

Ruby/Tk:: date.grid_columnconfigure(1, :weight=>1)
Ruby/Tk:: TkGrid.columnconfigure(date, 1, :weight=>1)
Tcl/Tk :: grid columnconfigure date 1 -weight 1

NOTE: ‘date’ in the case of Tcl/Tk means the widget path of

the ‘date’ frame widget.

In those cases, the master is the frame widget ‘date’.
And the index is 1, that is, the 2nd column of the grid table.
( the index of 1st column is 0. )

The default weight value of each column is 0.
All of those columns aren’t assigned free area arised from
resizing the master (‘date’ frame).
So, the small grid table is placed at the center of the master,
and has free areas at each side.

After calling the columnconfigure, the free area is allocated
by the weight ratio ( column0 : column1 = 0 : 1 ).
It enlarges the width of column1 only.
And now, the ‘sticky’ option gets the chance of working.
The area of the column1 is larger than the size of the label widget.
The label widget is placed depend on the value of ‘sticky’ option.

And the index is 1, that is, the 2nd column of the grid table.
( the index of 1st column is 0. )

That’s what I was missing. I was thinking the index value was for the
frames within root, not the columns. I think I’ve got it now. Thanks
again.

-j