perl - Get all the word enter in text widget to an array -
i new tk/perl. below simple gui interface create using tk/perl.
below part of code create gui.
$f2_label=$f_frame_top0->label(-text=>"file",-font=>[-family=>'ms sans serif',-size=>9,-weight=>'bold',-underline=>0],-justify=>'left')->pack(-side=>'left',-anchor=>'w',-padx=>1,-pady=>1,); $f2_entry=$f_frame_top0->entry(-width=>50,-state=>"normal")->pack(-side=>'left',-anchor=>'w',-padx=>1,-pady=>1,-fill=>'x',-expand=>1); $f2_file_btn=$f_frame_top0->button(-text=>"...", -height=>1, -width=>2, -command=> [\&file_search,$tab2,$f2_entry,"txt"])->pack(-side=>'left',-anchor=>'w',-padx=>1,-pady=>1); $f3_label=$f_frame_top1->label(-text=>"number",-font=>[-family=>'ms sans serif',-size=>9,-weight=>'bold',-underline=>0],-justify=>'left')->pack(-side=>'left',-anchor=>'w',-padx=>1,-pady=>1,); $f3_entry=$f_frame_top1->text(-width=>10,-height=>10,-wrap=>'word',-state=>"normal")->pack(-side=>'left',-anchor=>'w',-padx=>1,-pady=>1,-fill=>'x',-expand=>1); $but1_close=$f_frame_bot->button(-text=>"close",-command=>sub {destroy $mw}) ->pack(-side=>"right",-anchor=>'e',-padx=>1,-pady=>1); $but1_exe=$f_frame_bot->button(-text=>"run",-command=>[\&fablot_fusesort,$f2_entry,$f3_entry] ) ->pack(-side=>"right",-anchor=>'e',-padx=>1,-pady=>1); sub fablot_fusesort{ $file1 = shift -> get(); $number = shift ->get(); }
i want number user enter in text (the 22,23,24,25,26) process in subroutine not able shift -> get(). way can number user enter in text widget? helping
the correct syntax get()
method on tk::text
object described in documentation tk::text
:
$text->get(index1, ?index2?)
return range of characters text. return value characters in text starting 1 index
index1
, ending before 1 indexindex2
(the character @index2
not returned). ifindex2
omitted single character @index1
returned. if there no characters in specified range (e.g.index1
past end of file orindex2
less or equalindex1
) empty string returned
so using get()
without argument error.
here example of how text:
use strict; use warnings; use tk; $mw = mainwindow->new(); $entry = $mw->text( -width=>20, -height => 10, -wrap => 'word', -state => "normal" )->pack( -padx => 1, -pady => 1, -fill => 'x', -expand => 1 ); $button = $mw->button( -text => "run", -command=> sub { fablot_fusesort($entry) } )->pack( -padx => 1, -pady => 1 ); sub fablot_fusesort{ ( $entry) = @_; $text = $entry->get('1.0','end'); # <-- gets text in widget print "$text"; } mainloop;
Comments
Post a Comment