Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Newbie Tk Data collection Question

by bblustein (Beadle)
on Apr 10, 2003 at 19:14 UTC ( #249717=perlquestion: print w/replies, xml ) Need Help??

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

Ok, here's my question. I'm sure it's got a relatively easy answer, but I'm not sure how to approach this.

I've set up a TK Form that tracks different parts and various statistics about those parts (quantity on hand, part #, orders for that part, supplier, etc.). I'm trying to set up a daily update form that just displays a form with a basic "part number" : "Quantity" entry box, with the current quantity inserted into the entry as a starting value.

@partnames is an array I populate with all the parts I'm currently tracking, @quantity has the quantities.
Here's my code:

foreach (@partnames) { $j++; } for ($i=0; $i < $j; $i++) { $xv = $leftframe->Frame()->pack; $v = $xv->Label(-text => "$partnames[$i]", -justify => 'right' +)->pack(-side => 'right'); $w = $rightframe->Entry(-width => '5', -background => 'White') +->pack; $w -> insert('end', $quantity[$i]); }
Now, this comes out how I want it, an entry and label for each part, with it's quantity entered as a starting value.

Now, the user will go through the paperwork, and update the quantities for each part.

I know how to use a simple $variable = $entry->get statement, but in this case, each entry is named $w. How do I pull the numbers in the entry into an array so I can spit them back into the database I have set up?

Thank you for your help.

Replies are listed 'Best First'.
Re: Newbie Tk Data collection Question
by hiseldl (Priest) on Apr 10, 2003 at 22:58 UTC

    Basically all you need to do is pass the reference of your quantity array to the textvariable option. The quantity array should have the same index as the corresponding part number. Note that this will overwrite the values in your quantity array, so if you want to keep the original values then you will need to copy them to a different array and use that array as the textvariable reference. Here's an example:

    use Tk; use Tk::LabEntry; use strict; use warnings; my $top = MainWindow->new(); my @form = (); my @partname = ("Widget One", "Widget Two", "Widget Thr"); my @quantity = (11 , 22 , 33 ); for(my$i=0; $i<@partname; $i++) { $form[$i] = $top->LabEntry(-label => "$partname[$i]", ##### note the reference to the -textvariable, it is ##### a reference to your quantity array with the ##### index that corresponds to the part number -textvariable => \$quantity[$i], )->pack; } MainLoop; ##### here I just dump the values to stdout for(my$i=0; $i<@partname; $i++) { print "Part: $partname[$i], New Quantity: ", $quantity[$i],"\n"; $i++; }
    download this code and try it. Change the values from 11, 22, 33 to whatever you want, then exit and look at the values that are dumped, they should be the same as what you typed in.

    --
    hiseldl
    What time is it? It's Camel Time!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249717]
Approved by sschneid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-05-26 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?