hi all,
I need small help related to radio buttons in perl/TK.
This is my code.
sub setup { chomp; $fr_indx = shift; print "STRING: $_\n"; ($type, $name, .......) = split(/,/,$_); $f_filler = $f[$fr_indx]->Label(-text=>" ")->pack(-side=>'top' +,-pady => 0, -padx => 0); $f_switch{$name} = $f[$fr_indx]->Frame->pack(-side => 'top'); $f_switch_label{$name} = $f_switch{$name}->Label( -text => $name, )->pack(-side=>'top'); # Creation of Radiobuttons $f_filler = $f[$fr_indx]->Label(-text=>" ")->pack(-side=>'top',-pa +dy => 0, -padx => 0); #added $f_switch_radio{$name} = $f_switch{$name}->Radiobutton( -text => 'AUTO ', -value => 'auto' , -highlightbackground => black, #-selectcolor => green, -variable => \$f_switch_val{$name}, -command => [\&f_mode], )->pack(-side=>'right',-pady => '0'); if (index($type,"Toggle")>=0) { $f_switch_radio{$name}->bind("<Button>", [\&toggle_off,$name]); $f_switch_val{$name} = 'off'; } else { $f_switch_radio{$name}->bind("<Button>",[\&f_off,$name]); } $f_filler = $f_switch{$name}->Label(-text => " ") ->pack(-side=>'left',-pady => 0, -padx => 0); $f_switch_radio{$name} = $f_switch{$name}->Radiobutton( -text => 'MAN ', -value => 'man' , -highlightbackground => black, #-selectcolor => green, -variable => \$f_switch_val{$name}, -command => [\&f_mode] )->pack(-side=>'right',-pady => '0') ->select(); }
I am creating two radiobuttons "auto" and "man", for each entry in config file.$type and $name , i am reading from config file. For radiobuttons, variable is given as $f_switch_val{$name} hash.
Callback for both the radiobuttons "auto" and "man" is below:
sub f_mode { my $ref = shift; my $name = shift; #For each key value check the value of radio button value while ( my ($name, $value) = each(%f_switch_val) ) { #If "Manual" button is clicked, then do the following if ($f_switch_val{$name} eq "man"){ # Do this } #If "Auto" button is clicked, then do the following elsif ($f_switch_val{$name} eq "auto"){ #Do this } } }
My problem here is , for each radiobutton click, i am checking the hash "%f_switch_val", hence while loop has to multiple iterations.if there are 20 entries in the hash, for each radio button click, loop has to run for 20 times.
I am using while loop because i dont know the exact key corresponding to that radio button.
Can anyone suggest better way to do this.
Thanks, Harika
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |