Hi folks, i was asked to make a gui front end for my recent perl program. I chose perl/Tk which i'm totally new to. However, i was really impressed how quickly i was able to knock something up just by cutting and pasting a few examples i found on the web!

Anyway, the gist of my question is: If i have a couple of radio buttons, how do i set the gui so that part of it is greyed out or (preferably) disappears when one of the radio buttons is pressed?

I've tried searching through examples (there's a lot of good examples) but i can't find any which do this sort of thing! Apologies for the really long post. I hope it's clear. Thanks!

This is the full program/gui:

#!/usr/bin/perl -w use strict; use warnings; use Tk; # Main Window my $mw=new MainWindow; $mw->title("Analog Test Mux Generator"); # Framed Radio buttons at top to choose output #============================================ my $output_select="netlist"; #-------------------------------------------- my $frame=$mw->LabFrame( -label=> "Ouput Select", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); $frame->Radiobutton( -variable=>\$output_select, -value=>'netlist', -text=>'Generate Netlist', ) ->pack(-side=>'left'); $frame->Radiobutton( -variable=>\$output_select, -value=>'template', -text=>'Generate Template', ) ->pack(-side=>'right'); #============================================ my $input_filename; my $sheet_number; my $project_name; #-------------------------------------------- my $netlist_args_frame=$mw->LabFrame( -label=> "Netlist Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $netlist_input_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_input_frame->Label( -text=>'Input Filename:' )->pack(-side=>'left'); $input_filename=$netlist_input_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $netlist_sheet_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_sheet_frame->Label( -text=>'Sheet Name/Number:', )->pack(-side=>'left'); $sheet_number=$netlist_sheet_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $netlist_proj_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_proj_frame->Label( -text=>'Project Name:', )->pack(-side=>'left'); $project_name=$netlist_proj_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- #============================================ my $template_output_filename; my $template_project_name; my $template_pin_list; #-------------------------------------------- my $template_args_frame=$mw->LabFrame( -label=> "Template Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $template_output_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_output_frame->Label( -text=>'Template Filename:', )->pack(-side=>'left'); $template_output_filename=$template_output_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $template_proj_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_proj_frame->Label( -text=>'Project Name:', )->pack(-side=>'left'); $template_project_name=$template_proj_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $template_pins_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_pins_frame->Label( -text=>'Template Pins:', )->pack(-side=>'left'); $template_pin_list=$template_pins_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- #============================================ my $import_working_directory; my $import_ref_lib; my $import_dest_lib; #-------------------------------------------- my $import_args_frame=$mw->LabFrame( -label=> "Import Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $import_dir_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_dir_frame->Label( -text=>'Working Directory:', )->pack(-side=>'left'); $import_working_directory=$import_dir_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $import_ref_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_ref_frame->Label( -text=>'Reference Library:', )->pack(-side=>'left'); $import_ref_lib=$import_ref_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $import_dest_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_dest_frame->Label( -text=>'Destination Library:', )->pack(-side=>'left'); $import_dest_lib=$import_dest_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- #============================================ #============================================ my $merge_option=0; my $spares_option=0; #-------------------------------------------- my $options_frame=$mw->LabFrame( -label=> "Additional Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); my $merge_check=$options_frame->Checkbutton( -text=>"Merge Output Controls", -variable=>\$merge_option ) ->pack(-side=>'left'); $merge_check->deselect(); my $spares_check=$options_frame->Checkbutton( -text=>"Add Spare Cells", -variable=>\$spares_option ) ->pack(-side=>'right'); $spares_check->deselect(); #============================================ my $exit = $mw->Button(-text => 'Exit', -command => sub { exit; }); $exit->pack(-side => 'bottom', -expand => '1', -fill => 'x'); # my $generate = $mw->Button(-text => 'Generate', -command => sub { generate(); }); $generate->pack(-side => 'bottom', -expand => '1', -fill => 'x'); MainLoop; #print "Hello World\n"; # subroutines: sub generate { my $input_filename=$input_filename->get; my $project_name=$project_name->get; my $sheet_number=$sheet_number->get; my $template_output_filename=$template_output_filename->get; my $template_project_name=$template_project_name->get; my $template_pin_list=$template_pin_list->get; my $import_working_directory=$import_working_directory->get; my $import_ref_lib=$import_ref_lib->get; my $import_dest_lib=$import_dest_lib->get; print "---------------------------------------------\n"; print "Input = $input_filename\n"; print "Sheet = $sheet_number\n"; print "Project = $project_name\n"; print "---------------------------------------------\n"; print "Template File = $template_output_filename\n"; print "Template Project = $template_project_name\n"; print "Template Pins:\n"; print "$_\n" foreach (split ', ', $template_pin_list); print "---------------------------------------------\n"; print "Working Directory = $import_working_directory\n"; print "Ref Lib = $import_ref_lib\n"; print "Dest Lib = $import_dest_lib\n"; print "---------------------------------------------\n"; } __END__

I'd like when pressing the "Netlist" radio button at the top, for the "template" input fields do dissappear.

Then when pressing "Template" radibutton, the opposite, so only the "template" input fields would be present (and of course, the 2 buttons in both cases)

So the gui for the netlist radio button having been pressed would look like:

#!/usr/bin/perl -w use strict; use warnings; use Tk; # Main Window my $mw=new MainWindow; $mw->title("Analog Test Mux Generator"); # Framed Radio buttons at top to choose output #============================================ my $output_select="netlist"; #-------------------------------------------- my $frame=$mw->LabFrame( -label=> "Ouput Select", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); $frame->Radiobutton( -variable=>\$output_select, -value=>'netlist', -text=>'Generate Netlist', ) ->pack(-side=>'left'); $frame->Radiobutton( -variable=>\$output_select, -value=>'template', -text=>'Generate Template', ) ->pack(-side=>'right'); #============================================ my $input_filename; my $sheet_number; my $project_name; #-------------------------------------------- my $netlist_args_frame=$mw->LabFrame( -label=> "Netlist Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $netlist_input_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_input_frame->Label( -text=>'Input Filename:' )->pack(-side=>'left'); $input_filename=$netlist_input_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $netlist_sheet_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_sheet_frame->Label( -text=>'Sheet Name/Number:', )->pack(-side=>'left'); $sheet_number=$netlist_sheet_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $netlist_proj_frame=$netlist_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $netlist_proj_frame->Label( -text=>'Project Name:', )->pack(-side=>'left'); $project_name=$netlist_proj_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- #============================================ #my $template_output_filename; #my $template_project_name; #my $template_pin_list; ##-------------------------------------------- #my $template_args_frame=$mw->LabFrame( #-label=> "Template Input Options", #-labelside=>'acrosstop', #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #my $template_output_frame=$template_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$template_output_frame->Label( #-text=>'Template Filename:', #)->pack(-side=>'left'); #$template_output_filename=$template_output_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $template_proj_frame=$template_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$template_proj_frame->Label( #-text=>'Project Name:', #)->pack(-side=>'left'); #$template_project_name=$template_proj_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $template_pins_frame=$template_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$template_pins_frame->Label( #-text=>'Template Pins:', #)->pack(-side=>'left'); #$template_pin_list=$template_pins_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #============================================ my $import_working_directory; my $import_ref_lib; my $import_dest_lib; #-------------------------------------------- my $import_args_frame=$mw->LabFrame( -label=> "Import Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $import_dir_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_dir_frame->Label( -text=>'Working Directory:', )->pack(-side=>'left'); $import_working_directory=$import_dir_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $import_ref_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_ref_frame->Label( -text=>'Reference Library:', )->pack(-side=>'left'); $import_ref_lib=$import_ref_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $import_dest_frame=$import_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $import_dest_frame->Label( -text=>'Destination Library:', )->pack(-side=>'left'); $import_dest_lib=$import_dest_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- #============================================ #============================================ my $merge_option=0; my $spares_option=0; #-------------------------------------------- my $options_frame=$mw->LabFrame( -label=> "Additional Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); my $merge_check=$options_frame->Checkbutton( -text=>"Merge Output Controls", -variable=>\$merge_option ) ->pack(-side=>'left'); $merge_check->deselect(); my $spares_check=$options_frame->Checkbutton( -text=>"Add Spare Cells", -variable=>\$spares_option ) ->pack(-side=>'right'); $spares_check->deselect(); #============================================ my $exit = $mw->Button(-text => 'Exit', -command => sub { exit; }); $exit->pack(-side => 'bottom', -expand => '1', -fill => 'x'); # my $generate = $mw->Button(-text => 'Generate', -command => sub { generate(); }); $generate->pack(-side => 'bottom', -expand => '1', -fill => 'x'); MainLoop; #print "Hello World\n"; # subroutines: sub generate { my $input_filename=$input_filename->get; my $project_name=$project_name->get; my $sheet_number=$sheet_number->get; #my $template_output_filename=$template_output_filename->get; #my $template_project_name=$template_project_name->get; #my $template_pin_list=$template_pin_list->get; my $import_working_directory=$import_working_directory->get; my $import_ref_lib=$import_ref_lib->get; my $import_dest_lib=$import_dest_lib->get; print "---------------------------------------------\n"; print "Input = $input_filename\n"; print "Sheet = $sheet_number\n"; print "Project = $project_name\n"; #print "---------------------------------------------\n"; #print "Template File = $template_output_filename\n"; #print "Template Project = $template_project_name\n"; #print "Template Pins:\n"; #print "$_\n" foreach (split ', ', $template_pin_list); print "---------------------------------------------\n"; print "Working Directory = $import_working_directory\n"; print "Ref Lib = $import_ref_lib\n"; print "Dest Lib = $import_dest_lib\n"; print "---------------------------------------------\n"; } __END__

and the "Template" Radio button pressed would look like this:

#!/usr/bin/perl -w use strict; use warnings; use Tk; # Main Window my $mw=new MainWindow; $mw->title("Analog Test Mux Generator"); # Framed Radio buttons at top to choose output #============================================ my $output_select="template"; #-------------------------------------------- my $frame=$mw->LabFrame( -label=> "Ouput Select", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); $frame->Radiobutton( -variable=>\$output_select, -value=>'netlist', -text=>'Generate Netlist', ) ->pack(-side=>'left'); $frame->Radiobutton( -variable=>\$output_select, -value=>'template', -text=>'Generate Template', ) ->pack(-side=>'right'); #============================================ #my $input_filename; #my $sheet_number; #my $project_name; ##-------------------------------------------- #my $netlist_args_frame=$mw->LabFrame( #-label=> "Netlist Input Options", #-labelside=>'acrosstop', #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #my $netlist_input_frame=$netlist_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$netlist_input_frame->Label( #-text=>'Input Filename:' #)->pack(-side=>'left'); #$input_filename=$netlist_input_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $netlist_sheet_frame=$netlist_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$netlist_sheet_frame->Label( #-text=>'Sheet Name/Number:', #)->pack(-side=>'left'); #$sheet_number=$netlist_sheet_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $netlist_proj_frame=$netlist_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$netlist_proj_frame->Label( #-text=>'Project Name:', #)->pack(-side=>'left'); #$project_name=$netlist_proj_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #============================================ my $template_output_filename; my $template_project_name; my $template_pin_list; #-------------------------------------------- my $template_args_frame=$mw->LabFrame( -label=> "Template Input Options", -labelside=>'acrosstop', ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- my $template_output_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_output_frame->Label( -text=>'Template Filename:', )->pack(-side=>'left'); $template_output_filename=$template_output_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $template_proj_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_proj_frame->Label( -text=>'Project Name:', )->pack(-side=>'left'); $template_project_name=$template_proj_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- my $template_pins_frame=$template_args_frame->Frame( ) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); #-------------------------------------------- $template_pins_frame->Label( -text=>'Template Pins:', )->pack(-side=>'left'); $template_pin_list=$template_pins_frame->Entry( # Width is in characters not in pixels -width=>35, )->pack(-side=>'right'); #-------------------------------------------- ##============================================ #my $import_working_directory; #my $import_ref_lib; #my $import_dest_lib; ##-------------------------------------------- #my $import_args_frame=$mw->LabFrame( #-label=> "Import Input Options", #-labelside=>'acrosstop', #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #my $import_dir_frame=$import_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$import_dir_frame->Label( #-text=>'Working Directory:', #)->pack(-side=>'left'); #$import_working_directory=$import_dir_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $import_ref_frame=$import_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$import_ref_frame->Label( #-text=>'Reference Library:', #)->pack(-side=>'left'); #$import_ref_lib=$import_ref_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- #my $import_dest_frame=$import_args_frame->Frame( #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); ##-------------------------------------------- #$import_dest_frame->Label( #-text=>'Destination Library:', #)->pack(-side=>'left'); #$import_dest_lib=$import_dest_frame->Entry( ## Width is in characters not in pixels #-width=>35, #)->pack(-side=>'right'); ##-------------------------------------------- ##============================================ ##============================================ #my $merge_option=0; #my $spares_option=0; ##-------------------------------------------- #my $options_frame=$mw->LabFrame( #-label=> "Additional Options", #-labelside=>'acrosstop', #) ->pack(-expand=> '1', -fill=>'both', -side=>'top'); # #my $merge_check=$options_frame->Checkbutton( #-text=>"Merge Output Controls", #-variable=>\$merge_option #) ->pack(-side=>'left'); #$merge_check->deselect(); # #my $spares_check=$options_frame->Checkbutton( #-text=>"Add Spare Cells", #-variable=>\$spares_option #) ->pack(-side=>'right'); #$spares_check->deselect(); # #============================================ my $exit = $mw->Button(-text => 'Exit', -command => sub { exit; }); $exit->pack(-side => 'bottom', -expand => '1', -fill => 'x'); # my $generate = $mw->Button(-text => 'Generate', -command => sub { generate(); }); $generate->pack(-side => 'bottom', -expand => '1', -fill => 'x'); MainLoop; #print "Hello World\n"; # subroutines: sub generate { #my $input_filename=$input_filename->get; #my $project_name=$project_name->get; #my $sheet_number=$sheet_number->get; my $template_output_filename=$template_output_filename->get; my $template_project_name=$template_project_name->get; my $template_pin_list=$template_pin_list->get; #my $import_working_directory=$import_working_directory->get; #my $import_ref_lib=$import_ref_lib->get; #my $import_dest_lib=$import_dest_lib->get; #print "---------------------------------------------\n"; #print "Input = $input_filename\n"; #print "Sheet = $sheet_number\n"; #print "Project = $project_name\n"; print "---------------------------------------------\n"; print "Template File = $template_output_filename\n"; print "Template Project = $template_project_name\n"; print "Template Pins:\n"; print "$_\n" foreach (split ', ', $template_pin_list); print "---------------------------------------------\n"; #print "Working Directory = $import_working_directory\n"; #print "Ref Lib = $import_ref_lib\n"; #print "Dest Lib = $import_dest_lib\n"; #print "---------------------------------------------\n"; } __END__

Sorry for the huge post i tried to make it as clear as possible! Thanks for any help you could provide.


In reply to 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.