Checking for selected text 
Author Message
 Checking for selected text

This sounds llike a pretty simple one; but I can't figure it out. I need to
check the selection status of a text widget. If something is selected then do
something, otherwise do something else. Checking 'sel.first' or 'sel.last'
just errors out. What else is available that returns a value I can use without
giving an error?

Thanks,
Ola

==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the

--




Fri, 20 Nov 1998 03:00:00 GMT  
 Checking for selected text

Quote:

> This sounds llike a pretty simple one; but I can't figure it out. I need to
> check the selection status of a text widget. If something is selected then do
> something, otherwise do something else. Checking 'sel.first' or 'sel.last'
> just errors out. What else is available that returns a value I can use without
> giving an error?

just put the check for selected text into an eval:

use Tk;
$w=new MainWindow;
$t=$w->Text;
$t->pack;
$t->insert('end',`ls`);
$b=$w->Button(-text=>'test', -command =>\&t)->pack;
MainLoop;

sub t{
   my $g;
   eval {$g=$t->get('sel.first','sel.last')};
   if(defined($g)){
        print STDERR $g,"\n";
   }
   else{
        print "nothing selected.\n";
   }

Quote:
}

-------------------------------------------------------------------------------
    __________  __      
   /   ______/ / /   Martin Kraegeloh
  |   /       / /   Computervision Deutschland GmbH
  |   \      / /   Carl-Zeiss-Ring 5
  |    \    / /   85737 Ismaning
  |     \  / /   Tel. ...89 96071 128
  |      \/ /   Fax  ...89 96071 155 (PC) or 106 (Paper)
   \_______/        
-------------------------------------------------------------------------------

==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the

--




Sat, 21 Nov 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Checking for marked or selected text in a Text widget

2. After doing a select check question.

3. Selecting a random line from a text file

4. Loop for selecting text?

5. Randomly selecting lines of text?

6. Selecting part of a text file

7. Selecting blocks of text from a flat file

8. Appearance of Selected text in TextUndo

9. Problem selecting text with keyboard - Tk-b8

10. Colors in Text widget and select colors

11. How to select in a Text widget?

12. Text search and select again

 

 
Powered by phpBB® Forum Software