selection

selection , a Tk command, manipulates the X selection.

Synopsis

selection option ?arg arg ...?

Supported subcommands are:

selection clear ?-displayof window? ?-selection selection?
selection get ?-displayof window? ?-selection selection? ?-type type?
selection handle ?-selection selection? ?-type type? ?-format format? window command
selection own ?-displayof window? ?-selection selection?
selection own ?-command command? ?-selection selection? window

Documentation

official reference

Description

Can someone write up some text distinguishing the terms for 'inter-widget text highlighting for copy/paste purposes' and 'user initiated indication of widget component indication' - in other words, distingushing the concept of 'selecting text in a text widget or whatever' vs 'selecting listbox items'...

Utf-8 Characters

DKF: Sometimes you need to get UTF-8 characters through the selection (especially the clipboard) on Unix/X11. Tk's default bindings handle most of this automatically for you, but sometimes you need to do a bit more.

This is because the STRING selection type (selections can have many types at once) does not properly support anything other than ASCII for historic reasons. A standard introduced a while back to work around this problem uses the UTF8_STRING selection type instead (and that causes string data to be sent as utf-8, which we handle just nicely) and we support exporting the data using that type automatically: you don't need to do anything to make that work. But when reading a selection, you have to handle it manually (Tk's default bindings do this for you normally, but they're just scripted). The correct way to do this is, when looking to get a string from the selection, to try to read the get the selection with type UTF8_STRING first, and only if that fails fall back to using STRING.

Replacing xv_gset_se

LV: On Solaris, under the old Open Windows , there was a command called xv_get_sel whose purpose was to return the text that the user had selected . With Solaris 9, that command was no longer available. My first cut at replacing it is:

#! /usr/bin/env tclsh
package require Tk
wm withdraw .
set selContents [selection get -selection PRIMARY]
puts $selContents
exit

I don't know whether the original command also checked the secondary and clipboard targets or not. This does what I needed - if someone needs more functionality, the code is here to extend.

See Also

clipboard
label selection
listbox selection
Primary Transfer vs. the Clipboard