Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

by golux (Friar)
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017878]
[marto]: good morning all
[Corion]: Hi marto!
[Corion]: The fun show at $work continues, as The Big Project is now in its second week of frantic live-bugfixing and weekend releases where nobody knows what went live. Nothing has been tested anyway.
erix mutters cantankerously under his breath
Corion watches from the sidelines. Or rather, from behind, as my system only gets output from that process and my programs adhere strictly to the GIGO design principle.
[erix]: ah, that's nice to hear Corion :)
[Corion]: erix: Yeah, the sad thing is that all I can do is document things, so I can point fingers when the auditors come :-/
[Corion]: "I'm here to open tickets and point fingers. And I'm all out of tickets."
[erix]: didn't Sybase have pretty good auditing? :) (this is a vague memory)
[erix]: (culprits often are upstream of db of course)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-03-28 08:57 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (328 votes). Check out past polls.