I started a Tk calculator script a day or two ago and I nearly have it. I've already posted here but I feel that this problem could be better addressed on its own.
I am getting this error from the script
Uncaught exception from user code: Can't call method "Button" on an undefined value at C:\Documents and S +ettings\Eoin\Desktop\calc.pl line 52.
From what I understand from the error is that it is saying that  $rows[$r] is undefined. Where as @rows is quite clearly defined, as is $r.

UPDATE: I've discovered that the error is being caused by having the function button chars (i.e. * n* - \ + =) in the array for $i
for my $i ( qw/ 7 8 9 * n* 4 5 6 - \ 1 2 3 + = 0 . C / )
Now i'm really confused!!


Heres the rest of it.
my $mw = new MainWindow(-title => 'Calc'); $mw->geometry("300x300"); my $topframe = $mw->Frame(-height => '60', -width => '300')->pack(-sid +e => 'top', -expand => '0', -fill => 'x' +); my $btmframe = $mw->Frame(-height => '225', -width => '300',)->pack(-s +ide => 'left', -expand => '1', -fill => +'both'); push @rows, $btmframe->Frame()->pack( -expand => 1, -fill => 'both', - +side => 'top') 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 = 0; 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} = $rows[$r]->Button(-text => "$i", -width => '3', -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;
If anyone has any ideas on whats causing the problem, feel free to let me know. All and any help is greatly appriciated. :)

Cheers, Eoin...

In reply to Undefined Button method?? by eoin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.