and it was getting an undef value in there.qw/ 7 8 9 * n* 4 5 6 - \ 1 2 3 + = 0 . C / ) {
I'm not going to do your project for you. The code below is a patched up version of your code, which runs. Getting the rows setup right is up to you. Switch to grid, or setup separate frames for your rows of buttons.
#!/usr/bin/perl use Tk; use warnings; use strict; my %button; my $calc = 0; my $mw = new MainWindow( -title => 'Calc' ); $mw->geometry("300x300"); my $topframe = $mw->Frame( -height => '60', -width => '300' ) ->pack( -side => 'top', -expand => '0', -fill => 'x' ); my $btmframe = $mw->Frame( -height => '225', -width => '300', ) ->pack( -side => 'left', -expand => '1', -fill => 'both' ); push my @rows, $btmframe->Frame()->pack( -expand => 1, -fill => 'both', -side => 't +op' ) for ( 0 .. 3 ); my $display = $topframe->Entry( -justify => 'right', -state => 'disabled', -textvariable => \$calc )->pack( -expand => '1', -fill => 'x', -pady => 30, -padx => 20, -side => 'right' ); $mw->bind( "<KeyRelease>", sub { &keypress } ); my $r = 1; my $h = 1; my $w = 1; for my $i (qw/ 7 8 9 * n* 4 5 6 - \ 1 2 3 + = 0 . C / ) { if ( $i eq '+' || $i eq '=' ) { $h = 2; } ########LINE 52 BELOW################ $button{$i} = $mw->Button( -text => "$i", -width => '1', -height => "$h", # -command => sub { &btnpress($i) } )->pack( -expand => 1, -fill => 'both', -padx => 2, -pady => 2, -side => 'left', -ipadx => 5, -ipady => 5 ); $w++; $h = 1; if ( $w > 2 ) { $w = 0; $r++; } } MainLoop;
In reply to Re: Undefined Button method??
by zentara
in thread Undefined Button method??
by eoin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |