# Ruby tk grid question

**URL:** <https://www.ruby-forum.com/t/ruby-tk-grid-question/61574>\
**Category:** Ruby\
**Created:** [May 25, 2006, 4:31am UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574 "2006-05-25T04:31:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdruse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jdruse](https://www.ruby-forum.com/u/jdruse)\
**Post date:** [May 25, 2006, 4:31am UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574/1 "2006-05-25T04:31:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdruse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jdruse](https://www.ruby-forum.com/u/jdruse)\
**Post date:** [May 25, 2006, 9:55am UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574/2 "2006-05-25T09:55:52Z")

</div>

From: Jon D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: ruby tk grid question  
Date: Thu, 25 May 2006 11:31:45 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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) ).

---

<div class="post-metadata">

**Author:** ![jdruse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jdruse](https://www.ruby-forum.com/u/jdruse)\
**Post date:** [May 25, 2006, 10:31am UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574/3 "2006-05-25T10:31:57Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![jdruse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jdruse](https://www.ruby-forum.com/u/jdruse)\
**Post date:** [May 25, 2006, 11:14am UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574/4 "2006-05-25T11:14:28Z")

</div>

From: Jon D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: ruby tk grid question  
Date: Thu, 25 May 2006 17:32:09 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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.

---

<div class="post-metadata">

**Author:** ![jdruse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b38774/32.png) [@jdruse](https://www.ruby-forum.com/u/jdruse)\
**Post date:** [May 25, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/ruby-tk-grid-question/61574/5 "2006-05-25T21:11:22Z")

</div>

> 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
