Copyright © tutorialspoint.com
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.
Here is a simple syntax to create this widget:
TkLabel.new(root) { .....Standard Options.... .....Widget-specific Options.... } |
These options have been described in previous chapter.
SN | Options with Description |
---|---|
1 | height => Integer Specifies a desired height for the label. |
2 | width => Integer Specifies a desired width for the label. |
When a new label is created, it has no default event bindings: labels are not intended to be interactive.
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 following result
Copyright © tutorialspoint.com