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


In reply to GUI issue by harika123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.