Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Changing or Modifying a Tk Gui on pressing a radiobutton

by golux (Pilgrim)
on Feb 08, 2013 at 19:24 UTC ( #1017878=note: print w/ replies, xml ) Need Help??


in reply to Changing or Modifying a Tk Gui on pressing a radiobutton

Hi Amblikai,

Here's how you could create a data structure defining regions to reveal/hide when the corresponding RadioButton is pressed.

First, assign variables to your RadioButtons. For example:

my $rb1 = $frame->Radiobutton( -variable=>\$output_select, -value=>'netlist', -text=>'Generate Netlist', ) ->pack(-side=>'left'); my $rb2 = $frame->Radiobutton( -variable=>\$output_select, -value=>'template', -text=>'Generate Template', ) ->pack(-side=>'right');
Later in the program, after you've defined ALL the widgets which you want to hide/reveal (but before the MainLoop), create your data structure:
# Data structure to control 'hideable' regions # # Each key is a valid RadioButton. Each value is a list of widgets # to REVEAL when that RadioButton is clicked, at which time all other # widgets ((in other Array Refs) will be hidden. ## my $a_reveal = [ [ $rb1 => [ $netlist_args_frame, $import_args_frame, $options_fram +e ] ], [ $rb2 => [ $template_args_frame ] ], ]; assign_hideable_widgets($a_reveal);
Finally, in your subroutine section, create the subroutine which sets up the callbacks for each RadioButton, to hide or reveal the specific widgets (in this case, they're all LabFrames):
sub assign_hideable_widgets { my ($a_reveal) = @_; # Return if no hideable regions defined @$a_reveal or return; # Save all hideable regions my $a_all = [ ]; # List of all widgets my $h_seen = { }; # Hash all widgets seen my $h_reveal = { }; # Maps RadioButton to widgets to reveal my $h_packinfo = { }; # Saves each widget's pack information # Create closure to hide/reveal desired regions my $c_hide = sub { my ($rb) = @_; # First, unpack everything map { $_->packForget } @$a_all; # Next, pack selected widgets for this RadioButton my $a_reveal = $h_reveal->{$rb}; foreach my $w (@$a_reveal) { my $a_pack = $h_packinfo->{$w}; $w->pack(@$a_pack); } }; # Iterate each RadioButton and the widget(s) it reveals foreach my $a_item (@$a_reveal) { my ($rb, $a_reveal) = @$a_item; $h_reveal->{$rb} = $a_reveal; # Save all widgets and their pack info foreach my $w (@$a_reveal) { $h_seen->{$w}++ or push @$a_all, $w; $h_packinfo->{$w} = [ $w->packInfo ]; } $rb->bind("<Button-1>" => sub { $c_hide->($rb) }); } }

say  substr+lc crypt(qw $i3 SI$),4,5


Comment on Re: Changing or Modifying a Tk Gui on pressing a radiobutton
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-11-26 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (171 votes), past polls