beetlebug▾
/

selection

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

SubcommandDescription
selection ownGives the owner of a selection, or makes a window the owner.
selection clearRemoves the owner of a selection.
selection handleSets the script that gives the data of a selection that a window owns.
selection getGives 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

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also