I'm still trying to explore TK's abilities. Right now, I'm working on an input screen that features multiple rows of "parts", with a current inventory on hand, and an additional box used for adding to the total for each part. For purposes of clarity on my intent, I'll put it this way: I'll be recieving reports of inventory on X number of parts (it will be variable by day) from different storerooms. Each one will have a random amount of each part. So I need a form that will list each part, and have a running total column, and an entry to add new qty in each time. So, here's the code:
#!/usr/bin/perl use Tk; @parts = ("11111", "22222", "33333", "44444", "55555"); @labels = (); @entries = (); @add_boxes = (); $main = new MainWindow; $i = 0; $k = 0; while ($parts[$i]) { $labels[$i] = $main->Label(-text => "$parts[$i]")->grid(-column => + '0', -row => $k); $entries[$i] = $main->Entry(-background => 'white', -width => 8)-> +grid(-column => '1', -row => $k); $entries[$i]->insert('end', '0'); $add_boxes[$i] = $main->Entry(-background => 'white', -width => 8) +->grid(-column => '2', -row => $k); $add_boxes[$i]->bind("<Return>", sub { $currentqty = $entries[$i]->get; $addqty = $add_boxes[$i]->get; $resultqty = $currentqty + $addqty; $entries[$i]->delete('0.0', 'end'); $add_boxes[$i]->delete('0.0', 'end'); $entries[$i]->insert('end', $resultqty); $main->update }); $i++; $k++; } MainLoop;
This doesn't work - the sub routine does not add the number in. What's worse, I know why it doesn't work (it evaluates $i at the time you run, and at that point, $i is not a valid value for those arrays). I just don't know how to make this work as I intend.

UPDATE: Thank you very much, merlyn and jdporter. You have given me the solution that evaded me (and as usual, seems so simple in retrospect. My hindsight remains 20/20). I thank you both for your excellent advice. <Bows>

In reply to 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.