First off, your code had a sneaky error in which resulted from you not using warnings and strict. Specifically
my $lam_num_ent = $lam_mat_frm -> Entry(), -variable=> \$lam_num;
slips thru and runs without warnings and strict enabled. This results in the entry textvariable not working as expected. It should be
my $lam_num_ent = $lam_mat_frm -> Entry(-textvariable=> \$lam_num);

To solve the "variable in name" problem, use hashes. In the code below, I only put the Optionmenu widgets in a hash, but for a decent program, you should put all information related to each Optionmenu into a hash, like this for example:

my %ort_optmen; $ort_optmen{$num}{'widget'} = whatever $ort_optmen{$num}{'variable'} = whatever $ort_optmen{$num}{'options'} = whatever
That way, all you need to know is $num, and you can get all the information about that Optionmenu widget.

So here is a basic fix to show you the way.

#!/usr/bin/perl use warnings; use strict; use Tk; # Variables my $lam_num; my $ort1; my $ort2; my $ort3; # Main Window my $mw = new MainWindow; # Build GUI my $lam_mat_frm = $mw -> Frame(); my $lam_num_ent = $lam_mat_frm -> Entry(-textvariable=> \$lam_num); my %ort_optmen; #create hash to hold the optionmenu widgets $ort_optmen{1} = $lam_mat_frm -> Optionmenu(-options => [qw(-45 0 45 9 +0)], -variable => \$ort1); $ort_optmen{2} = $lam_mat_frm -> Optionmenu(-options => [qw(-45 0 45 9 +0)], -variable => \$ort2); $ort_optmen{3} = $lam_mat_frm -> Optionmenu(-options => [qw(-45 0 45 9 +0)], -variable => \$ort3); for(1..3){ $ort_optmen{$_} -> configure(-state => 'disabled'); } my $lam_data_button = $lam_mat_frm->Button(-text=>"Input Laminate Data +", -command=> \&input_lam_data); # Geometry Management $lam_mat_frm -> grid(-row=>1, -column=>1, -columnspan=>2); $lam_num_ent -> grid(-row=>1,-column=>1); $ort_optmen{1} -> grid(-row=>2,-column=>1); $ort_optmen{2} -> grid(-row=>3,-column=>1); $ort_optmen{3} -> grid(-row=>4,-column=>1); $lam_data_button -> grid(-row=>5,-column=>1); MainLoop; sub input_lam_data { print "$lam_num\n"; #reset them all off to begin with foreach (1..3){ $ort_optmen{$_} -> configure(-state => 'disabled'); } # you need to do some valid range checking for $lam_num here # I leave that to you foreach my $num (1..$lam_num){ $ort_optmen{$num} -> configure(-state => 'normal'); } }
</c>

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

In reply to Re^3: Optionmenu Variable in Name by zentara
in thread Optionmenu Variable in Name by shortyfw06

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.