Hi All,
[ win98se, build 521, tk 800.022 ]
I've built a grid of buttons:
foreach my $jarow ( 0..$r ) {
foreach my $jacol ( 0..$c ) {
my $this_butt = 'b_' . $jarow . '_' . $jacol;
${ this_butt } = $mw->Button(
-image => $white,
-command => [ \&flip2, \${ this_butt }, $this_butt ]
)
->grid ( -row=>$jarow, -column=>$jacol );
${ this_butt }->bind("<Button-3>", [
\&right_click, $this_butt ] );
}
}
with names like b_3_5, that represent a button in row
3 and col 5.
When a user clicks on a button, subroutine flip2, and
it's subs, will change the current image and then
check a 2d array and determine which adjacent buttons,
if any, should have their images changed from $white
to $gray. Suppose cell 3,6 indicates that button
b_3_6 should be changed to $gray.
In this case I want to check the current image for
b_3_6 and if it is not $gray, then change it to $gray
and save the 3,6 location for more processing. The
check for $gray is important since it limits the
possibilities to a small number of cases and prevents
a repeating loop. Here is what I have so far:
sub check_cell {
# should this image be changed?
my ( $r, $c ) = @_; # row and col.
my $butt = 'b_' . $r . '_' . $c; # b_3_6
my $img = ${ butt }->cget( '-image' ); # what is
curr img?
if ( $img ne $gray ) {
${ butt }->configure( -image => $gray);
push @possible, join('_', $r, $c);
}
}
The fourth line:
my $img = ${ butt }->cget( '-image' );
consistently fails.
Here are various tries and their error msg:
# ${ butt } error msg: Can't locate object method
"cget" via package b_2_1 at ...
# ${ $butt } error msg: Can't use string (b_4_0) as a
scalar ref while "strict refs" in use...
# ${ \butt } error msg: Bareword "butt" not allowed
while "strict subs" in use at ...
# ${ \$butt } error msg: Can't locate object method
"cget" via package b_7_1 at ...
# ${ "butt" } error msg: Can't use string ("butt") as
a scalar ref while "strict refs" in use...
# $butt error msg: Can't locate object method
"cget" via package b_3_1 at ...
# \$butt error msg: Can't locate object method
"cget" via package b_0_1 at ...
Method cget works in other subroutines, for example:
sub right_click {
# A mouse right-click will 'cycle thur' these three
images.
my ( $name ) = @_;
my $curr = $name->cget( '-image' );
if ( $curr eq $white ) { $name->configure( -image
=> $flag ); }
elsif ( $curr eq $flag ) { $name->configure( -image
=> $ques ); }
elsif ( $curr eq $ques ) { $name->configure( -image
=> $white ); }
}
I've read Chapter 8, References, in Camel, and related
doc pages for ref, toot, and obj, but it just has not
jelled yet. I'm new to Tk, oo, and references. What
am I doing wrong?
---
Jim
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs