label - package of label routines, including selection and wrapping.
package require label ?0.0.1?
label::button1 W
label::copy W
label::cut W
label::paste W
label::select W
label::wrap W w
label::pkginit_
The label package provides routines for label text selection and auto-wrapping.
Sometimes it is useful to be able to select the text in Tk label widgets. This package enables you to do this. Many people prefer an entry or text widget with its -state option set to disabled for implementing a UI component that supports selection but not modification. However, this library can be loaded to provide the selection capability without modifying any source code. Labels also provide features not supported in entry widgets (for example, compound images), while requiring a (slightly) smaller memory footprint.
In addition, this package provides the facility for labels to auto-wrap to fit available horizontal space. This is somewhat similar to the -wrap option for Tk text widgets, but the difference is that you cannot vertically scroll labels - the whole label widget is always visible.
- label::button1 W
- Sets the input focus to label widget W (if the -takefocus option returns true).
- label::copy W
- Copies label W's text to the clipboard.
- label::cut W
- Copies label W's text to the clipboard, and then delete the label's text.
- label::paste W
- Sets label W's text to the contents of the clipboard.
- label::select W
- Sets the label's -state option to active, and copies the label text to the primary selection.
- label::wrap W w
- Configures label W's -wraplength option to fit within horizontal screen width w. This can be done whenever the label is resized, in response to a <Configure> event. See EXAMPLE below.
- label::pkginit_
- This private command initializes the label package.
This package creates class bindings for the Label class that provide the following behaviour:
- [1]
- Clicking mouse button1 sets the input focus to this label widget (if the -takefocus option returns true). This action is carried out by the label::button1 command.
- [2]
- Double clicking with mouse button 1 sets the label's -state option to active, and copies the label text to the primary selection. This action is carried out by the label::select command.
- [3]
- Control-x generates the <<Cut>> virtual event.
- [4]
- Control-c generates the <<Copy>> virtual event.
- [5]
- Control-v generates the <<Paste>> virtual event.
- [6]
- The <<Cut>> virtual event copies the label's text to the clipboard and deletes the label's text. This action is carried out by the label::cut command.
- [7]
- The <<Copy>> virtual event copies the label's text to the clipboard. This action is carried out by the label::copy command.
- [8]
- The <<Paste>> virtual event sets the label's text to the contents of the clipboard. This action is carried out by the label::paste command.
package require label
label .l1 -text "This is a label with some text"
# Make sure the label fills available horizontal space
pack .l1 -fill x -padx 20 -pady 20
# For auto-wrapping
bind .l1 <Configure> [list label::wrap %W %w]
Needs more testing.
Copyright (C) 2003, Mark G. Saye <markgsaye@yahoo.com>