Hi, I just want to point out that you are better off designing things with hashes, instead of arrays. The hashes are easier to deal with in loops, and if you ever decide to turn it into a module, your hash is ready to turn into a namespace. Also, you should let the "-textvariables" do the hard work of updating for you. You can keep your %parts hash in a separate file too, and when you load your script, you can load the %parts hash, and another file containing $parts{$part}{'needed'} values, and they will just fill themselves in, because of the -textvariables. Look at this:
#!/usr/bin/perl use warnings; use strict; use Tk; require Tk::Pane; my %parts = ( 11111 => { 'total' => 95, 'add' => 0, 'needed' => 2 }, 22222 => { 'total' => 100, 'add' => 0, 'needed' => 0 }, 33333 => { 'total' => 800, 'add' => 0, 'needed' => 20 }, 44444 => { 'total' => 1000, 'add' => 0, 'needed' => 25 }, 55555 => { 'total' => 10, 'add' => 0, 'needed' => 2 }, 66666 => { 'total' => 95, 'add' => 0, 'needed' => 2 }, 77777 => { 'total' => 100, 'add' => 0, 'needed' => 0 }, 88888 => { 'total' => 800, 'add' => 0, 'needed' => 20 }, 99999 => { 'total' => 1000, 'add' => 0, 'needed' => 25 }, 10101 => { 'total' => 10, 'add' => 0, 'needed' => 2 }, ); my $mw = new MainWindow; my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'e', ) ->grid; #header for my $part ( keys %parts ){ $pane->Label( -text => ' part ' )->grid( -row => 0, -column => 0 ) +; $pane->Label( -text => ' total ' )->grid( -row => 0, -column => 1 ) +; $pane->Label( -text => ' needed ' )->grid( -row => 0, -column => 2 ) +; $pane->Label( -text => ' add ' )->grid( -row => 0, -column => 3 ) +; } my $row = 0; for my $part ( sort keys %parts ) { $row++; $pane->Label( -text => $part )->grid( -row => $row, -column => 0 ); $pane->Label( -textvariable => \$parts{$part}{'total'} ) ->grid( -row => $row, -column => 1 ); $pane->Label( -textvariable => \$parts{$part}{'needed'} ) ->grid( -row => $row, -column => 2 ); $parts{$part}{'entry'} = $pane->Entry( -textvariable => \$parts{$part}{'add'} ) ->grid( -row => $row, -column => 3 ); $parts{$part}{'entry'}->bind ("<Return>", sub { process_add( $part ) }); } MainLoop; sub process_add { my $part = shift; $parts{$part}{'total'} += $parts{$part}{'add'}; $parts{$part}{'needed'} -= $parts{$part}{'add'}; $parts{$part}{'add'} = 0; }

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

In reply to Re: I need help making loop-created buttons and entries match up... by zentara
in thread I need help making loop-created buttons and entries match up... by bblustein

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.