O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 selection

  • Using 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required