in reply to Re: Re: Re: Re: Syntax error using Tk
in thread Syntax error using Tk
#!/perl/bin/perl -w use strict; use Tk; use Tk::Button; use Tk::Entry; my $row = 0; my $column = 0; my $calc = "0.00"; my $buffer; my %button; my $mw = new MainWindow(-title => 'Calc', -bg => 'blue'); $mw->geometry("300x300"); my $topframe = $mw->Frame(-height => '40', -width => '300', -bg => 'bl +ack'); $topframe->pack(-side => 'top', -expand => '0', -fill => 'x', -anchor, + 'nw'); my @rows; push @rows, $mw->Frame()->pack( -expand, 1, -fill, 'both', -side, 'top +', -padx, 3, -pady,3) for (0..3); my $display = $topframe->Entry(-justify => 'right', -state => 'disabled', -textvariable => \$calc) ->pack(-expand => '1', -pady => '20', -padx => '30', -fill => 'x', -side => 'left'); $mw->bind("<KeyRelease>" , sub { &keypress } ); my $r =0; my $w = 0; for my $i ( qw/ 7 8 9 4 5 6 1 2 3 0 . C / ) { $button{$i} = $rows[$r] ->Button(-text => "$i", -width => '3', -height => '1', -command => sub { &btnpress($i) }) ->pack( -expand, 1, -fill, 'both', -side, 'le +ft', -padx, 2); $w++; if( $w == 3){ $r++; $w= 0; } } MainLoop; sub btnpress{ my $num = shift; if($num ne "C"){ $buffer .= $num; $calc = sprintf "%0.2f", $buffer; } if($num eq "C"){ $calc = "0.00"; $buffer = 0.00; } } sub keypress{ my $widget = shift; my $e = $widget->XEvent; # get event object my $key = $e->K; $key=~s/period/\./ig; if( $key =~/c/ig ){ $key = uc $key; $button{$key}->invoke; } if( $key =~/(\d)|\./){ &numpress($key); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Syntax error using Tk
by eoin (Monk) on Feb 18, 2004 at 12:19 UTC | |
by JamesNC (Chaplain) on Feb 18, 2004 at 16:03 UTC |