- Ruby Basics
- Ruby - Home
- Ruby - Overview
- Ruby - Environment Setup
- Ruby - Syntax
- Ruby - Classes and Objects
- Ruby - Variables
- Ruby - Operators
- Ruby - Comments
- Ruby - IF...ELSE
- Ruby - Loops
- Ruby - Methods
- Ruby - Blocks
- Ruby - Modules
- Ruby - Strings
- Ruby - Arrays
- Ruby - Hashes
- Ruby - Date & Time
- Ruby - Ranges
- Ruby - Iterators
- Ruby - File I/O
- Ruby - Exceptions
- Ruby Advanced
- Ruby - Object Oriented
- Ruby - Regular Expressions
- Ruby - Database Access
- Ruby - Web Applications
- Ruby - Sending Email
- Ruby - Socket Programming
- Ruby - Ruby/XML, XSLT
- Ruby - Web Services
- Ruby - Tk Guide
- Ruby - Ruby/LDAP Tutorial
- Ruby - Multithreading
- Ruby - Built-in Functions
- Ruby - Predefined Variables
- Ruby - Predefined Constants
- Ruby - Associated Tools
- Ruby Useful Resources
- Ruby - Quick Guide
- Ruby - Useful Resources
- Ruby - Discussion
- Ruby - Ruby on Rails Tutorial
Ruby/TK - The pack geometry manager
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.
fill − The fill option is used to specify whether a widget should occupy all the space given to it by the parent window or the widget. Some of the possible values that can be used with this option are none, x, y, or both. By default, the fill option is set to none.
expand − The expand option is used to specify whether a widget should expand to fill any extra space available. The default value is 0, which means that the widget is not expanded. The other value is 1.
side − The side option is used to specify the side against which the widget is to be packed. Some of the possible values that can be used with this option are top, left, bottom, or right. By default, the widgets are packed against the top edge of the parent window.
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 the following result−
To Continue Learning Please Login
Login with Google