in reply to Re: tk image map like button with hover effect
in thread tk image map like button with hover effect

I will do like this... but Probably, I'm missing something.
#!/usr/bin/perl use strict; use warnings; use Tk; my($mw,$img1,$img2,$c,$btn,$id); $mw = MainWindow->new; $c = $mw->Canvas(-width => 400,-height =>200,-background=>'black')->pa +ck; $img1=$c->Photo(-file=>'but1.gif'); $img2=$c->Photo(-file=>'but2.gif'); $btn=$c->Button( -command=>sub{exit;}, -image=>$img1)->pack; $id=$c->createWindow(200,150, -window=>$btn); $btn->bind('<Enter>', => sub{ $btn->configure(-image=>$img2);} ); $btn->bind('<Leave>', => sub{ $btn->configure(-image=>$img1);} ); MainLoop;

Replies are listed 'Best First'.
Re^3: tk image map like button with hover effect
by pashanoid (Scribe) on Jul 04, 2011 at 13:39 UTC
    This code is very nice and simple, thank you! However, is there any way to get rid of the border that makes up the button? I like it, but the guy I'm doing this for will certainly not.

      Now that you have the basics, it's time to read the documentation :)

      $ perldoc Tk::Button BUTTON(1) User Contributed Perl Documentation B +UTTON(1) NAME Tk::Button - Create and manipulate Button widgets SYNOPSIS $button = $parent->Button(?options?); STANDARD OPTIONS -activebackground -activeforeground -anchor -background -bitmap -borderwidth -compound -cursor -disabledforeground -font -foreg +round -highlightbackground -highlightcolor -highlightthickness -image -justify -padx -pady -relief -repeatdelay -repeatinterval -take +focus -text -textvariable -underline -wraplength See Tk::options for details of the standard options.

      borderwidth is described in Tk::options:

      Name: activeBorderWidth Class: BorderWidth Switch: -activeborderwidth Specifies a non-negative value indicating the width of the +3-D border drawn around active elements. See above for definit +ion of active elements. The value may have any of the forms accep +table to Tk_GetPixels. This option is typically only available in w +idgets displaying more than one element at a time (e.g. menus but +not buttons).

      Further digging is up to you.

      As a side note: the book Mastering Perl/Tk is a very good reference. Learning Perl/Tk is not.


      Enjoy, Have FUN! H.Merijn