Dandello has asked for the wisdom of the Perl Monks concerning the following question:

First off - many thanks to all who have already helped iron out the bugs in what was supposed to be a simple programming project.

Next up: I want to populate the rest of the table created by

#Geometry Management my $table = $mw->Frame (); my $lab4 = $mw->Label( -text => "Year" )->pack(); my $mpy_0 = $mw->Entry( -width => 5, -textvariable => \$mpy0 )->pack() +; my $lab5 = $mw->Label( -text => "Momentary\nPop. Est." )->pack(); my $mpe_0 = $mw->Entry( -width => 5, -textvariable => \$mpe0 )->pack() +; $lab4 -> grid(-row=>1,-column=>1, -in => $table); $lab5 -> grid(-row=>1,-column=>2, -in => $table); $mpy_0 -> grid(-row=>2,-column=>1, -in => $table); $mpe_0 -> grid(-row=>2,-column=>2, -in => $table); foreach my $b (0 .. $LST-1){ print $mpy_mpe[$b]; } $table->pack ();

$LST is an imported integer. @mpy_mpe has already been opened and contains

my $mpy_1 = $mw->Entry( -width => 5, -textvariable => \$mpy1 )->pack() +;\n$mpy_1 -> grid(-row=>3,-column=>1, -in => $table)\n;my $mpe_1 = $m +w->Entry( -width => 5, -textvariable => \$mpe1 )->pack();\n$mpe_1 -> +grid(-row=>3,-column=>2, -in => $table)\n; my $mpy_2 = $mw->Entry( -width => 5, -textvariable => \$mpy2 )->pack() +;\n$mpy_2 -> grid(-row=>4,-column=>1, -in => $table)\n;my $mpe_2 = $m +w->Entry( -width => 5, -textvariable => \$mpe2 )->pack();\n$mpe_2 -> +grid(-row=>4,-column=>2, -in => $table)\n;
(Basically each line contains the code for both the $mpe and $mpy widgets since they go together.)

I'm sure it's a simple step I'm missing but

foreach my $b (0 .. $LST-1){ print $mpy_mpe[$b]; }
only prints to the DOS window, not to MainWindow.

Needless to say, it doesn't do much good in the DOS window.

Replies are listed 'Best First'.
Re: One More bit of Perl/Tk Confusion
by Dandello (Monk) on Jan 28, 2011 at 01:05 UTC

    Solved it.

    my @mpy = (); my @mpe = (); my @mpya = (); my @mpea = (); foreach my $drp ( 0 .. $LST ) { my $row = $drp + 2; $mpy[$drp] = $mw->Entry( -width => 5,-textvariable =>\$mpya[$drp] +)->pack(); $mpy[$drp]->grid( -row => $row, -column => 1, -in => $table ); $mpe[$drp] = $mw->Entry( -width => 5,-textvariable =>\$mpea[$drp]) +->pack(); $mpe[$drp]->grid( -row => $row, -column => 2, -in => $table ); }

    At least it prints to the MainWindow properly

    Now, why this didn't work the first time I tried it, I have no idea.

      Now, why this didn't work the first time I tried it, I have no idea.

      I may be wrong here, since all I ever use is pack, BUT I believe that you can't mix geometry managers, like pack and grid.... use one or the other, or expect odd results.


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

        That and I probably need new glasses. Funny how '{' and '[' look alike after a while. :)

        BUT, the project is working and I don't have to spend a weekend configuring Wampserver on my son's computer at school.

Re: One More bit of Perl/Tk Confusion
by Anonymous Monk on Jan 27, 2011 at 18:38 UTC
    What is $mpy_mpe? You only print to filehandles, the default selected handle, STDOUT, often ends in a DOS windows, Tk widgets usually don't have a print method, you usually use insert method

      $mpy_mpe[$b]is item $b in the array @mpy_mpe. In this case $mpy_mpe[0] = my $mpy_1 = $mw->Entry( -width => 5, -textvariable => \$mpy1 )->pack();\n$mpy_1 -> grid(-row=>3,-column=>1, -in => $table);\nmy $mpe_1 = $mw->Entry( -width => 5, -textvariable => \$mpe1 )->pack();\n$mpe_1 -> grid(-row=>3,-column=>2, -in => $table);\n

      Now, I can generate all 250+ rows that I need, but I only want to show the first 5, 10 or whatever is in $LST of them.

        Why not keep a count of how many you've added, and stop adding when the count gets too big?