Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-29 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found