Dear bretheren, I sincerely try not to bother you with silly stuff, but this one is beyond me... Boss used cut and paste with photoshop to "enhance" the buttons I made for him in my tk script. Now I have a but1.gif and a but2.gif and when a curser comes over this button it should become but2.gif, while normally it's a but1.gif. I'm building this with canvas and getting the ($x, $y) = $mw->pointerxy; coordinates to figure which image I should display. However, I'm unable to make the picture change. Here is the useless code I'm testing out the BUTTON with hover effect on:
#!/usr/bin/perl use warnings; use strict; use Tk::Trace; use Tk; my $mw = MainWindow->new; $mw->fontCreate('medium', -family=>'courier', -weight=>'bold', -size=> +int(-14*14/10)); my $c = $mw->Canvas(-width => 400,-height => 210,-bd => 2,-relief => ' +sunken',-background => 'black',)->pack; $c->createImage(150, 150, -image => $mw->Photo(-file => &update_meter, + -format => 'gif'), -anchor => 'ne', -tags => ['gif']); my $v = 0; $mw->traceVariable(\$v, 'w' => [\&update_meter]); $mw->bind('<Motion>' => sub{ $v += 1 }); my $text = $c->createText( 100,50, -text => $v,-font => 'medium', -fill => 'yellow', -an +chor => 's', -tags => ['text'] ); $c->raise('text'); MainLoop; sub update_meter { my($index, $value) = @_; my ($x, $y) = $mw->pointerxy; my $value_text = "$value x=$x y=$y"; $c->itemconfigure($text,-text => $value_text); my $file; my $file1 = '/home/pasha/perl/tk/but1.gif'; my $file2 = '/home/pasha/perl/tk/but2.gif'; if (($x > 103 && $x < 153) && ($y > 205 && $y < 226)){ #we are + over button $file = $file2; } else { $file = $file1; } }
The buttons are here: http://pashanoid.ru/images/but1.gif and http://pashanoid.ru/images/but2.gif if anyone is interested.
Thank you for your support and help!
In reply to tk image map like button with hover effect by pashanoid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |