#!/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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |