Copyright © tutorialspoint.com

Ruby/Tk - The pack geometry manager

previous next


Description:

The pack geometry manager organizes widgets in rows or columns inside the parent window or the widget. To manage widgets easily, the pack geometry manager provides various options, such as fill, expand, and side.

Syntax:

Here is a simple syntax to create a pack Widget:

 pack('padx'=>10, 'pady'=>10, 'side'=>'left')

Examples:

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

require 'tk'

top = TkRoot.new {title "Label and Entry Widget"}

#code to add a label widget
lb1 = TkLabel.new(top){
   text 'Hello World'
   background "yellow"
   foreground "blue"
   pack('padx'=>10, 'pady'=>10, 'side'=>'left')
}

#code to add a entry widget
e1 = TkEntry.new(top){
   background "red"
   foreground "blue"
   pack('padx'=>10, 'pady'=>10, 'side'=>'left')
}

Tk.mainloop

This will produce following result

Ruby/Tk Pack

previous next

Copyright © tutorialspoint.com