Clipboard and Selection Methods
Perl/Tk supports two kinds of
selection. They are named after the atoms that identify them:
CLIPBOARD
and PRIMARY
. Both
selection buffers are capable of handling arbitrary data, but they
default to simple ASCII text strings. Handling other data is beyond
the scope of this book, thus we confine the discussion to strings.
When making a selection, standard Perl/Tk widgets—such as Text
and Entry—select PRIMARY
and highlight the
selection. The widgets copy the selection to
CLIPBOARD
as well. This means that pasting text in
Tk works in either of two ways:
Using the middle button, which copies the
PRIMARY
selectionUsing the keyboard character Control-v, which copies the
CLIPBOARD
selection
Although we don’t talk about virtual
events until Chapter 15, participating widgets
(effectively) bind <<Copy>>
,
<<Cut>>
, and
<<Paste>>
virtual events to class
methods that manipulate the CLIPBOARD
selection.
The MainWindow generates virtual
<<Copy>>
,
<<Cut>>
, and
<<Paste>>
events when it sees the
characters Control-c, Control-x, and Control-v, respectively.
Applications differ as to which selection mechanism they use. The
tendency these days is to use the CLIPBOARD
and
the characters c
, x
, and
v
. What differs is the lead-in character. It may
be Control, Alt, or, on a Macintosh, the Apple key. Venerable Unix
applications tend to use PRIMARY
, where you copy
with button 1 and paste with button 2. Your mileage may vary.
Clipboard Methods
The following methods ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.