Is there a way to extract the label of that button in the menu, that the user clicks on,e.g. if the user clicks onmap { [Button => $_, -command => sub { replace($_) }] } @menu_items
I need to use a replace function to replace a word marked by the sel tag in a text widget by the label of the menu button.sub replace{ my $chosen="Label of button user clicked on"; + $t->insert('sel.first',"$chosen"); $t->delete('sel.first','sel.last'); $t->tagConfigure("rp",-foreground=>"black"); my $r=$t->search(-forwards,"$chosen",'end'); $t->tagAdd("rp","$r","$r wordend"); } 1;
I tried this but it keeps printing only the first label, i.e. "Foo", even when we click on other menu buttons.$m = $top->Menu(-tearoff => 0,font => "{arial} 12 {bold}", -menuitems => [ [Button => "$opt1", -command => \&replace1], [Button => "$opt2", -command => \&replace2], [Button => "$opt3", -command => \&replace3], ] ); sub replace1{ my $chosen1=$menu_items[0]; $t->insert('sel.first',"$chosen1"); $t->delete('sel.first','sel.last'); $t->tagConfigure("rp1",-foreground=>"black"); my $r1=$t->search(-forwards,"$chosen1",'end'); $t->tagAdd("rp1","$r1","$r1 wordend"); } 1; sub replace2{ my $chosen2=$menu_items[1]; ... } 1; sub replace3{ my $chosen3=$menu_items[2]; ... } 1;
Thanks in advance.sub replace{ my $chosen="$menu_items[$_]"; print "\nThe selected word:"; print "\n$chosen"; } 1;
In reply to Re: Re: Tk Menu question.
by perl_seeker
in thread Tk Menu question.
by perl_seeker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |