9.12. How do I select a range of tags in a Text widget?

A question arose concerning getting a range of selections from a Text widget. Nick Ing-Simmons' answer mentions several possibilities including:

Keyboard Copy/Paste 'is' implemented of course...

Subj:	RE: $Text->tag('ranges', 'sel') - does this work?

In <199512291957.OAA02609@ohm.nrl.navy.mil>
On Fri, 29 Dec 1995 14:57:42 -0500
Charles J Williams <chas@ohm.nrl.navy.mil> writes:
!I was writing a little tk perl today, and i decided to try to 
!implement a copy/paste using the 'sel' tag
!
!I enabled exportselection, and then try to probe the select 
!region with:
!
!    $buffer = $text->tag('ranges', 'sel');
!
!$buffer comes back with one entry, the end of the selection.
That is to be expected - the scalar gets assigned the last element of the list.

!I tried:
!
!    @buffer = $text->tag('ranges', 'sel');
!
!same difference.
This seems to work for me:
    ($start,$end) = $text->tagRanges('sel');
In perl/Tk ->tagRanges(...) is an alias for ->tag('ranges',...)

The following subroutine can also probe and print the tagRanges:

    sub showsel  
    { 
     my $text = @_;
     my @info = $text->tagRanges('sel');
     if (@info)
      {
       print "start=$info[0] end=$info[1]\n" 
      }
    }

Previous | Return to table of contents | Next