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

In reply to Re: Changing or Modifying a Tk Gui on pressing a radiobutton by golux
in thread Changing or Modifying a Tk Gui on pressing a radiobutton by Amblikai

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.