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

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.