Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

16.14. Selection Methods

Some widgets allow the user to make a selection. For example, the user can make a selection in the text, entry, and listbox widgets. You can manipulate the selection by using the following methods.

16.14.1. Clearing the Selection

To clear the current selection from any widget (this will also clear an X selection) use SelectionClear:

$widget->SelectionClear();

You can specify a -selection option, which takes either "PRIMARY" or "CLIPBOARD". The default is "PRIMARY". Using "CLIPBOARD" clears out the clipboard as well.

16.14.2. Getting the Selection

To determine what the current selection for the application is, use SelectionGet:

$selection = $widget->SelectionGet();

You can also specify the -selection option with the SelectionGetmethod:

$clipboard = $widget->SelectionGet(-selection => "CLIPBOARD");

The -selection method takes either "PRIMARY" or "CLIPBOARD". The default is "PRIMARY", so if you don't specify -selection, you will get back the value that represents the current selection in the application. Using "CLIPBOARD" will return the value in the clipboard.

16.14.3. Assigning a Callback

You can call SelectionHandle to assign a callback that will automatically be invoked when the selection associated with $win changes:

$widget->SelectionHandle($win => \&subroutine);

When $win owns the selection, the callback will be invoked (in this example, subroutine). You can specify the options -format, -type, and -selection with the same possible values shown ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata