Ruby/TK - The grid geometry manager



The grid geometry manager is the most flexible and easy-to-use geometry manager. It logically divides the parent window or the widget into rows and columns in a two-dimensional table.

You can then place a widget in an appropriate row and column format by using the row and column options, respectively. To understand the use of row and column options, consider the following example.


Here is a simple syntax to create a grid Widget:

grid('row'=>x, 'column'=>y)


Following is the code to display the Label and an Entry widget using the grid geometry manager:

require 'tk'

top = {title "Label and Entry Widget"}

#code to add a label widget{
   text 'Hello World'
   background "yellow"
   foreground "blue"
   grid('row'=>0, 'column'=>0)

#code to add a entry widget
e1 ={
   background "red"
   foreground "blue"
   grid('row'=>0, 'column'=>1)


This will produce the following result:

Ruby/Tk Grid