selection
Guide: Text
Gives a selection an owner window and a handler, and reads the data of a selection.
selection SUBCOMMAND ?ARG ...?
Description
A selection has a name, such as PRIMARY or CLIPBOARD. One window of the app can own each selection. The owner gives the data of the selection through a handler: a script that selection handle sets for the owner and a type, such as STRING. selection get runs the handler of the owner and gives its result.
The selections of ztk are in the app. ztk does not exchange the selection PRIMARY with other programs, as X11 does. The selection CLIPBOARD with no owner gives the text of clipboard.
The entry, the text, and the listbox do not take the selection PRIMARY when the user selects text in them. A script reads the selected text of such a widget with the commands of the widget.
Subcommands
| Subcommand | Description |
|---|---|
selection own | Gives the owner of a selection, or makes a window the owner. |
selection clear | Removes the owner of a selection. |
selection handle | Sets the script that gives the data of a selection that a window owns. |
selection get | Gives the data of a selection. |
Examples
% frame .f
> proc give {offset max} {
> string range "selected text" $offset [expr {$offset + $max - 1}]
> }
> selection handle .f give
> selection own .f
> selection get
selected text
Errors
% selection
wrong # args: should be "selection sub ?arg ...?"
-errorcode TCL WRONGARGS
% selection exists
bad option "exists": must be clear, get, handle, or own
-errorcode NONE
Differences from Tcl
- A widget with
-exportselection 1does not ownPRIMARYwhen the user or the script selects text in it, andselection getdoes not give that text. In Tk 8.6.16 on X11, the widget ownsPRIMARY, andselection owngives the widget. - A subcommand needs its full name:
selection ois an error. Tk 8.6.16 accepts a unique short form. - The errors have the
-errorcodeNONE, except a wrong count of arguments. Tk 8.6.16 gives codes such asTCL LOOKUP INDEX optionandTK SELECTION NONE.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1