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

The first and third modules of this modeling program and finished and working but I'm missing something obvious this module.

#!/usr/bin/perl # $Id: tkform2 $ # $Date: 1.26.11 $ # $HeadURL: adamant.net $ # $Revision: 2011 $ # $Source: /tkform2.pl $ ###################################################################### +############ use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use Tk; our $VERSION = 1.00; open my $DAT, '<', 'data/data1.txt' or croak 'cannot open data1'; my @data_in = <$DAT>; close $DAT or croak 'cannot close data1'; my ( $model, $initial, $copyerr, $LST, $file_id, $format, $tm, $for2 ) +; my $mpy0 = 0; my $mpe0 = 10; ( $model, $initial, $copyerr, $LST, $file_id, $tm, $format, ) = split +/[|]/xsm, $data_in[0]; if ( $format == 1 ) { $for2 = q{comma delimited}; } elsif ( $format == 2 ) { $for2 = q{tab delimited}; } my $mw = new MainWindow; $mw->geometry('500x600'); my $lab0 = $mw->Label( -text => "Model $model" )->pack(); my $lab1 = $mw->Label( -text => "Initial #: $initial" )->pack(); my $lab2 = $mw->Label( -text => "Copying Error % +/- $copyerr" )->pack +(); my $lab3 = $mw->Label( -text => "File Format - $for2" )->pack(); #Geometry Management 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); #$lab5 -> grid(-row=>1,-column=>2); #$mpy_0 -> grid(-row=>2,-column=>1); #$mpe_0 -> grid(-row=>2,-column=>2); my $button = $mw->Button( -text => "Submit", -command => \&somesub )->pack( -side => 'bottom' ); MainLoop; open my $DATABASE, '>', 'data/datatrans.txt' or croak 'datatrans not w +ritten.'; print {$DATABASE} qq{$model|$initial|$copyerr|$LST|$file_id|$format|$tm|$mpy0,|$mpe0,| +} or croak 'unable to print'; close $DATABASE or croak 'datatrans not closed.'; sub somesub { $, = "\n"; print "\nWorking\n"; $mw->destroy; } exit;

What I need, and can't seem to get to work, is: The $mpy_0..? series in a column under $lab4 and in the next column, the Smpe_0..? series under $lab5. When I try to put those into a frame ala my $frm_name = $mw -> Frame; with the $mw replaced by $frm_name just like in the tutorial, nothing appears - with or without the grid information.

When those widgets are not in a frame and the grid info is un-commented, the Tk window never appears. No warnings, just a blinking cursor in the DOS window.

I assume it's trying to do something.

What am I missing?

Replies are listed 'Best First'.
Re: More Perl/Tk confusion
by GrandFather (Saint) on Jan 27, 2011 at 01:45 UTC
    but I'm missing something obvious

    Yup, you are missing a stand alone sample that demonstrates the problem. At the very least a little sample data would help. It doesn't help that the code you do show demonstrates neither the frame related issue nor the non-frame related issue - it's somewhere between the two!

    However, reading somewhat between the lines, the following may get you to where you want to be:

    #!/usr/bin/perl use strict; use warnings; use Tk; my $mpy0 = 0; my $mpe0 = 10; my @data_in = <DATA>; my ($model, $initial, $copyerr, $LST, $file_id, $tm, $format,) = split + /[|]/xsm, $data_in[0]; my $for2; if ($format == 1) { $for2 = q{comma delimited}; } elsif ($format == 2) { $for2 = q{tab delimited}; } my $mw = MainWindow->new (); $mw->geometry ('500x600'); my $lab0 = $mw->Label (-text => "Model $model")->pack +(); my $lab1 = $mw->Label (-text => "Initial #: $initial")->pack +(); my $lab2 = $mw->Label (-text => "Copying Error % +/- $copyerr")->pack +(); my $lab3 = $mw->Label (-text => "File Format - $for2")->pack +(); #Geometry Management my $table = $mw->Frame (); my $lab4 = $mw->Label (-text => "Year"); my $mpy_0 = $mw->Entry (-width => 5, -textvariable => \$mpy0); my $lab5 = $mw->Label (-text => "Momentary\nPop. Est."); my $mpe_0 = $mw->Entry (-width => 5, -textvariable => \$mpe0); $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); $table->pack (); my $button = $mw->Button ( -text => "Submit", -command => \&somesub )->pack (-side => 'bottom'); MainLoop; print qq{$model|$initial|$copyerr|$LST|$file_id|$format|$tm|$mpy0,|$mp +e0,|}; exit; sub somesub { $, = "\n"; print "\nWorking\n"; $mw->destroy; } __DATA__ 1|0|0|0|0|0|1
    True laziness is hard work

      Packing the frame worked - but putting those widgets into a table (also packed, I noticed) should work too. Thanks

      Not a single one of the tutorials I found online referenced that little issue at all.

        Not a single one of the tutorials I found online referenced that little issue at all.

        So you learn, things are invisible until you tell the program to display them. There is also the powerful packForget, and siblings.

        See PerlTk geometry management , in case that wasn't one of the docs you scoured. It is the first hit that comes up when you google for "perlTk pack".


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: More Perl/Tk confusion
by PeterPeiGuo (Hermit) on Jan 27, 2011 at 01:16 UTC

    You need to pack that frame just like everything else.

    Peter (Guo) Pei

      Has anyone told you recently that you're a genius?