bblustein has asked for the wisdom of the Perl Monks concerning the following question:
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.#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need help making loop-created buttons and entries match up...
by merlyn (Sage) on Mar 25, 2005 at 14:09 UTC | |
|
Re: I need help making loop-created buttons and entries match up...
by jdporter (Paladin) on Mar 25, 2005 at 14:34 UTC | |
|
Re: I need help making loop-created buttons and entries match up...
by zentara (Cardinal) on Mar 25, 2005 at 16:24 UTC |