Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 chanting in the Monastery: (7)
As of 2024-04-19 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found