- 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 - Label Widget
Description
A label is a widget that displays text or images, typically that the user will just view but not otherwise interact with. Labels are used for such things as identifying controls or other parts of the user interface, providing textual feedback or results, etc.
A label can display a textual string, bitmap or image. If text is displayed, it must all be in a single font, but it can occupy multiple lines on the screen (if it contains newlines or if wrapping occurs because of the wraplength option) and one of the characters may optionally be underlined using the underline option.
Syntax
Here is a simple syntax to create this widget −
TkLabel.new(root) { .....Standard Options.... .....Widget-specific Options.... }
Standard Options
- anchor
- background
- bitmap
- borderwidth
- cursor
- font
- foreground
- highlightbackground
- highlightcolor
- highlightthickness
- image
- justify
- padx
- pady
- relief
- takefocus
- text
- textvariable
- underline
- wraplength
These options have been described in the previous chapter.
Widget Specific Options
Sr.No. | Options & Description |
---|---|
1 | height => Integer Specifies a desired height for the label. |
2 | width => Integer Specifies a desired width for the label. |
Event Bindings
When a new label is created, it has no default event bindings: labels are not intended to be interactive.
Examples
require 'tk' $resultsVar = TkVariable.new root = TkRoot.new root.title = "Window" Lbl = TkLabel.new(root) do textvariable borderwidth 5 font TkFont.new('times 20 bold') foreground "red" relief "groove" pack("side" => "right", "padx"=> "50", "pady"=> "50") end Lbl['textvariable'] = $resultsVar $resultsVar.value = 'New value to display' Tk.mainloop
This will produce the following result −