The subroutine tged is called when the button is clicked. Here is the code for the sub:$f->Button(-text => "Sug", -command =>\&tged)->pack(-side => 'right');
Before clicking the button 'Sug' which calls the tged subroutine, the user clicks another button which invokessub tged { @chars=$t->get('sel.first','sel.last'); + #Extract chars in area selected by user and store in @chars. #print "\nSelected word:"; #print @chars; open TF,'>gotword.txt' or die $!; #Write sel +ected word onto file. print TF @chars; close TF; $gotfile="gotword.txt"; #Save file +name in $gotfile. @sugs; #Array for + holding strings returned by &suggestcomb. @sugs=&suggestcomb($gotfile); #Call sub. &suggestcomb passing $gotfile as parameter. #print"\nStrings in main:"; #print "@sugs\n"; $top = new MainWindow; #Create new main window which pops up when #the user selects a word and clicks on the 'Sug' button. $lsugs=@sugs; #Length of + the array @sugs. $opt1="$sugs[$lsugs]"; #Last element in the suggestion array. $opt2="$sugs[$lsugs-1]"; #Second last element in the suggestion array. $opt3="$sugs[$lsugs-2]"; #Third last element in the suggestion array. $l = $top->Label(-text => "Press right button\nfor popup menu.")->pack +; #Text label for new main window. #Menu displayed in new main window. $m = $top->Menu(-tearoff => 0,font => "{arial} 12 {bold}", + -menuitems => #Menu items displ +ayed as buttons. [ [Button => "$opt1", -command => \&replace1], #Labels of buttons are the strings obtained from @sugs. [Button => "$opt2", -command => \&replace2], [Button => "$opt3", -command => \&replace3], ] ); #When a button is clicked the corresp. sub. for replacing is invoked. $top->bind("<Button-3>" => sub { $m->Popup(-popover => "cursor",-popan +chor => 'nw') }); } 1; #Subroutines to replac +e words with selected strings. sub replace1{ $chosen=$opt1; $t->insert('sel.first',"$chosen"); #Insert selected suggestion at the start point of the word to be repla +ced i.e. at sel.first. $t->delete('sel.first','sel.last'); #Delete the word to be replaced. $t->tagConfigure("replaced",-foreground=>"black"); $t->tagAdd("replaced","sel.first","sel.last"); } sub replace2{ $chosen=$opt2; $t->insert('sel.first',"$chosen"); $t->delete('sel.first','sel.last'); $t->tagConfigure("replaced",-foreground=>"black"); $t->tagAdd("replaced","sel.first","sel.last"); } sub replace3{ $chosen=$opt3; $t->insert('sel.first',"$chosen"); $t->delete('sel.first','sel.last'); $t->tagConfigure("replaced",-foreground=>"black"); $t->tagAdd("replaced","sel.first","sel.last"); }
Then the user selects a word which is in red colour, (the ' sel' tag gets that word)and clicks on the 'Sug' button.$t->tagConfigure("ch_clr",-foreground=>"red"); $t->tagAdd("ch_clr","$start","$end_pt");
**********$t->tagConfigure("replaced",-foreground=>"black"); $t->tagAdd("replaced","sel.first","sel.last");
Whew! That's about all .Please help$lsugs=@sugs; print"\nThe length of the array:"; print"\n$lsugs"; for($elt=0;$elt<$lsugs;$elt++) { pop(@sugs); } print"\nThe array contents after popping:"; print "@sugs\n";
In reply to Perl Tk Text widget question by perl_seeker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |