# Where is TkcGrid?

**URL:** <https://www.ruby-forum.com/t/where-is-tkcgrid/175210>\
**Category:** Ruby\
**Created:** [September 9, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210 "2009-09-09T19:21:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josef\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Josef\_W](https://www.ruby-forum.com/u/Josef_W)\
**Post date:** [September 9, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210/1 "2009-09-09T19:21:29Z")

</div>

Hello,

In Perl/Tk, tha canvas has a grid item type. Is this item type missing  
from  
the Ruby/Tk port? Using

TkcGrid.new([0,0], [10,10])

results in

./test.rb:17: uninitialized constant TkcGrid (NameError)

Any hints?

---

<div class="post-metadata">

**Author:** ![Josef\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Josef\_W](https://www.ruby-forum.com/u/Josef_W)\
**Post date:** [September 9, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210/2 "2009-09-09T19:38:28Z")

</div>

Josef W. wrote:

> Any hints?

TkGrid is used in many of the samples: sample/scrollframe.rb, for  
example.

---

<div class="post-metadata">

**Author:** ![Josef\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Josef\_W](https://www.ruby-forum.com/u/Josef_W)\
**Post date:** [September 9, 2009, 8:37pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210/3 "2009-09-09T20:37:36Z")

</div>

On Thu, Sep 10, 2009 at 02:37:43AM +0900, Joel VanderWerf wrote:

> > Any hints?
> 
> TkGrid is used in many of the samples: sample/scrollframe.rb, for example.

Thanks for your reply, Joel!

I am talking about the TkcGrid item type of the canvas widget and not  
about  
the TkGrid geometry manager. The TkcGrid item type draws little dots  
with  
a regular distance into the canvas.

---

<div class="post-metadata">

**Author:** ![Josef\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Josef\_W](https://www.ruby-forum.com/u/Josef_W)\
**Post date:** [September 9, 2009, 9:05pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210/4 "2009-09-09T21:05:06Z")

</div>

Josef W. wrote:

> > > Any hints?  
> > > TkGrid is used in many of the samples: sample/scrollframe.rb, for example.
> 
> Thanks for your reply, Joel!
> 
> I am talking about the TkcGrid item type of the canvas widget and not about  
> the TkGrid geometry manager. The TkcGrid item type draws little dots with  
> a regular distance into the canvas.

Oh, sorry! I don’t know, then. I’ve always constructed my own grids[1],  
so if you find the answer, let us know…

How is the perl class implemented? Google doesn’t have any hits for  
‘TkcGrid perl tk’, except your post.

[1] see mkgrid.rb in tkar/sample

---

<div class="post-metadata">

**Author:** ![Josef\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@Josef\_W](https://www.ruby-forum.com/u/Josef_W)\
**Post date:** [September 9, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/where-is-tkcgrid/175210/5 "2009-09-09T21:57:47Z")

</div>

On Thu, Sep 10, 2009 at 04:04:10AM +0900, Joel VanderWerf wrote:

> > > > ./test.rb:17: uninitialized constant TkcGrid (NameError)  
> > > > Oh, sorry! I don’t know, then. I’ve always constructed my own grids[1], so  
> > > > if you find the answer, let us know…

The grid item has some advantages over a matrix of dots:

- you don’t have to know in advance how big your canvas will be
- it automatically covers the whole cnavas whenever you resize it
- the grid dots never overlap other items
- grid dots will never be returned by search operations
- it is much more efficient than a matrix of dots. Having a canvas with  
10^6 dots makes a significant difference 🙂

> How is the perl class implemented?

I have no idea. I could not find any hints about that in my  
/usr/lib/perl5  
directory, so I assume it is implemented in the C bindings.

> Google doesn’t have any hits for ‘TkcGrid perl tk’, except your post.

Well, perl’s naming conventions for Tk are different from Ruby’s. Things  
like TkcXxxxx simply do not exist in Perl/Tk 😉

You might check section 9.6.10 in  
[http://docstore.mik.ua/orelly/perl3/tk/ch09\_06.htm](http://docstore.mik.ua/orelly/perl3/tk/ch09_06.htm)

Here’s the first part of the description from the Tk::Canvas man page

GRID ITEMS  
Items of type grid are intended for producing a visual reference for  
interpreting other items. They can be drawn as either lines (with  
dash  
style) or as rectangular “dots” at each grid point.

Items of type grid are unlike other items they always cover the whole  
of the canvas, but are never enclosed by nor overlap any area and are  
not near any point. That is they are intended to be always visible  
but  
not “pickable”, as such they do support the “active” state. They are  
like other items in that: multiple grids are permitted, they can be  
raised and lowered relative to other items, they can be moved and  
scaled. As yet grids do not apear in PostScript output.

Grids have outline like configure options. Grids are created with  
methods of the following form:

```
$canvas->createGrid(x1, y1, x2, y2, ?option, value, option, value, 

```

…?)

The arguments x1, y1 give the origin of the grid. x2, and y2 give the  
coordinates of the next grid point in their respective directions.  
After the coordinates there may be any number of option-value pairs,  
each of which sets one of the configuration options for the item.  
These same option-value pairs may be used in itemconfigure methods to  
change the item’s configuration. The following options are supported  
for grids:

[…]
