bass_warrior has asked for the wisdom of the Perl Monks concerning the following question:

Using Tk::ROText and Printing http://perlprint.sourceforge.net/

I am trying to set up two printing options from the menu, 1 to print everything in the text box:

$string = $resultbox->get('1.0', 'end'); $printer->print($string);

The 2nd to print only selected text:

$string = $resultbox->get('sel.first', 'sel.last'); $printer->print($string);

The issue I am having is determining if anything has been selected before calling get('sel.first', 'sel.last').
Any suggestions?
I tried something like:
if(defined ($resBox->get('sel.first')))

Which of course spits out the same error as when calling it to get the string with nothing selected.
Tk::Error: text doesn't contain any characters tagged with "sel"

Replies are listed 'Best First'.
Re: Tk::Text selection testing
by zentara (Cardinal) on Dec 03, 2004 at 20:11 UTC
    Tk::Error: text doesn't contain any characters tagged with "sel"

    Read the section for Selection in perldoc Tk::Text. You need to set "exportSelection =>1"


    I'm not really a human, but I play one on earth. flash japh
      I have exportselection set, how to I test to see if something is selected though?
      if ($txtbox->sel) { }
        The following works for me:
        use Tk; use strict; my $mw = MainWindow->new; $mw->title("Hello World"); my $txt = $mw->Text(-exportselection => 1); $txt->pack; $mw->Button(-text => "Done", -command => sub { if ($txt->getSelected) { print $txt->getSelected,"\n"; } else { print "No text selected\n"; } exit })->pack; MainLoop;