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

I just started using perl/tk and i needed to know how to get a string from a text widget, i used the get function but it did not work, here is my code, please help:
#!/usr/bin/perl -w use Tk; sub grab ; my $me = MainWindow->new; $menubar = $me -> Frame() -> pack('-side' => 'top','-fill' => 'x'); $filemenu = $menubar -> Menubutton('-text' =>'file') -> pack('-side' = +> 'left'); $filemenu -> command( -label => 'help', -command => sub{$text1->insert('1.0',"you clicked help.")}, -accelerator => 'ctrl+s', ); $filemenu->separator(); $filemenu->command('-label'=>'exit','-command'=>sub {exit}); $me->Button(-text => 'click', -command => sub{grab;} )->pack; $text1 = $me->Text ('-width'=>40, '-height'=> 1 )->pack; $me->Label(-text=> 'narmak' )->pack; $text2 = $me->Text ('-width'=>40, '-height'=> 1 )->pack; MainLoop; sub grab { my $take = $text1->get; $text2->insert('1.0',"$take"); }

Replies are listed 'Best First'.
Re: Perl/Tk help
by pfaut (Priest) on Jan 29, 2003 at 01:07 UTC

    The get() method requires arguments that specify a range of text to return from the widget. To get all the text, try my $take = $text1->get('1.0','end'); which says 'return all text from line 1 (the first line) character 0 (the first character) to the end'.

    More details in perldoc Tk::Text.

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
      thanks alot, it worked perfectly.