Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 sharing their wisdom with the Monastery: (4)
As of 2024-04-19 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found