in reply to Re: Tk::Text selection testing
in thread Tk::Text selection testing

I have exportselection set, how to I test to see if something is selected though?
if ($txtbox->sel) { }

Replies are listed 'Best First'.
Re^3: Tk::Text selection testing
by tall_man (Parson) on Dec 06, 2004 at 17:36 UTC
    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;
      Thanks, I was trying to use:
      $txt->get('sel.first', 'sel.last');


      and if nothing was selected Tk::Text was spitting out errors about sel.first not being defined.
      Using getSelected fixed that.