Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Re-Enter Data in Perl TK

by shortyfw06 (Beadle)
on Jul 09, 2012 at 14:57 UTC ( #980699=note: print w/ replies, xml ) Need Help??


in reply to Re: Re-Enter Data in Perl TK
in thread Re-Enter Data in Perl TK

Thank you very much for your honest and helpful response. I appreciate your guidance. I do not want my code to be convoluted. I want to learn how to write Perl efficiently. I've created a seperate frame as you suggested and added a reset button with gridForget on the popup frame. Everything is cleared and the widgets disappear when reset is activated, however, when I put in a new value, the widgets do not popup a second time. If there are any other suggestions you have to make my code less convoluted, please let me know so I can make it better.

#!/usr/bin/perl use warnings; use strict; use Tk; use Cwd; ###################################################################### +##################### # GUI Building ###################################################################### +##################### # make the selections available to the print_input_values sub my %t; my %mat; my %ort; my %mat_lab; my $scr; # Create Main Window my $mw = new MainWindow; my $lam_num; my $row=1; my $column=1; my $lam_mat_frm = $mw -> Frame(); $lam_mat_frm->grid(-row=>$row, -column=>$column,-columnspan=>6); my $lam_num_lab = $lam_mat_frm -> Label(-text=>"Input the number of pl +ies in the laminate.", -font=>"ansi 10 bold"); $lam_num_lab->grid(-row=>$row, -column=>$column); $column++; my $lam_num_ent = $lam_mat_frm -> Entry(-textvariable=> \$lam_num); $lam_num_ent->grid(-row=>$row, -column=>$column); $column++; my $lam_data_button = $lam_mat_frm->Button(-text=>"Input Laminate Data +", -command=> \&input_lam_data); $lam_data_button->grid(-row=>$row, -column=>$column); $column++; my $reset_button = $lam_mat_frm->Button(-text=>"Reset", -command=> \&do_reset); $reset_button->grid(-row=>$row, -column=>$column); $row++; my $lam_frm = $mw -> Frame(); $lam_frm->grid(-row=>$row,-column=>$column,-columnspan=>6); MainLoop; sub do_reset { $lam_num_ent->delete(0,'end'); $lam_frm->gridForget; } sub input_lam_data { $row=4; $column=2; my @lam_mat_t_lab = ( 'Material', 'Thickness', 'Orientation', ); my $n = 1; for my $label (@lam_mat_t_lab) { $mat_lab{$n} = $lam_frm -> Label (-text=> $label, -font=>"ansi 8 bold"); $mat_lab{$n}->grid(-row=>$row, -column=>$column); $column=$column+1; }; my %ply_lab; $n = 1; $row=5; do { $column = 1; $ply_lab{$n} = $lam_frm -> Label (-text=>"Ply $n", -font=>"ansi 8 bold"); $ply_lab{$n}->grid(-row=>$row,-column=>$column); $row = $row+1; $n = $n+1; } until ($n == $lam_num+1); # Create Material Optionmenus my @mats = ("PW","8HS","Tape"); my %mat_optmen; $n = 1; $row=5; $column=2; do { $mat_optmen{$n} = $lam_frm -> Optionmenu(-options => \@mats, -variable => \$mat{$n}); $mat_optmen{$n}->grid(-row=>$row,-column=>$column); $row=$row+1; $n = $n + 1; } until ($n == $lam_num+1); # Create Thickness Optionmenus my @ts = ("0.0077","0.0147","0.0054"); my %t_optmen; $n = 1; $row=5; $column=3; do { $t_optmen{$n} = $lam_frm -> Optionmenu(-options => \@ts, -variable => \$t{$n}); $t_optmen{$n}->grid(-row=>$row,-column=>$column); $row=$row+1; $n = $n + 1; } until ($n == $lam_num+1); # Create Orientation Optionmenus my @orts = ("-45","0","45","90"); my %ort_optmen; $n = 1; $row=5; $column=4; do { $ort_optmen{$n} = $lam_frm -> Optionmenu(-options => \@orts, -variable => \$ort{$n}); $ort_optmen{$n}->grid(-row=>$row,-column=>$column); $row=$row+1; $n = $n + 1; } until ($n == $lam_num+1); my $print_button = $lam_frm->Button(-text=>"Print BJSFM Input File +", -command=> \&print_input_file); $print_button->grid(-row=>$row,-column=>1); }


Comment on Re^2: Re-Enter Data in Perl TK
Download Code
Re^3: Re-Enter Data in Perl TK
by shortyfw06 (Beadle) on Jul 09, 2012 at 15:15 UTC

    I think I figured it out. Thanks! I added this to the do_reset sub.

    sub do_reset { $lam_num_ent->delete(0,'end'); $lam_frm->gridForget; $lam_frm = $mw -> Frame(); $lam_frm->grid(-row=>$row,-column=>$column,-columnspan=>6); }
      Now you are learning! :-) You ought to set a default value in your input entry to avoid the warning when the calculate button is pressed with nothing in the Entry.

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-12-21 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls