http://qs1969.pair.com?node_id=1144136

john.tm has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Is it possible to Bind an array of Buttons for <Enter> & <leave> With Tk::Zinc. There is no option for Activebackground in Zinc. I have a script with 30 buttons and would like them to change colour when the mouse enters or leave each button. I can do this for each button. but was wondering if there is a neater way.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Zinc; use Tk::Zinc::Graphics; my $mw = MainWindow->new(); $mw->withdraw; $mw->minsize(860,630); $mw -> FullScreen(1); $mw -> focusForce; $mw -> deiconify; my $arc_color = '=axial 20|#bdffa7;10 0|#000000;10 5|#bd0000;10 8|#b7f +fb7;10 40|#ffffff;10 91|#00ac00;10 95|#006700;10'; my @butns = ("buttonAA" .. "buttonAC"); $mw->geometry("860x630+100+60"); my $zinc = $mw->Zinc(-width => 860, -height => 630, -render => 1, -relief => 'flat', )->pack; my $tgroup = $zinc->add('group', 1); $zinc->coords($tgroup, [0,0]); #create at zinc origin $zinc->add('arc',$tgroup,[20,20,130,55], -filled => 1, -fillcolor => $arc_color, ); $zinc->add('text', 1, -position => [31, 30], -text => " admin", -color => "navyBlue", -spacing => 2, -tags=>['buttonAA'], ); #-------------------------------------- $zinc->add('arc',$tgroup,[20,59,130,90], -filled => 1, -fillcolor => $arc_color, ); $zinc->add('text', 1, -position => [29, 65], -text => "Print", -color => "navyBlue", -spacing => 2, -tags=>['buttonAB'], ); #------------------------------------- $zinc->add('arc',$tgroup,[20,94,130,125], -filled => 1, -fillcolor => $arc_color, ); $zinc->add('text', 1, -position => [34, 100], -text => "Form", -color => "navyBlue", -spacing => 2, -tags=>['buttonAC'], ); &setBindings; MainLoop; sub setBindings { $mw->Tk::focus(); $zinc->bind('buttonAA', '<1>', sub {&ButtonAA();}); $zinc->bind( 'buttonAA', '<Enter>', sub { $zinc->itemconfigure( 'buttonAA', -color => 'red'); }); $zinc->bind( 'buttonAA', '<Leave>', sub { $zinc->itemconfigure( 'buttonAA', -color => 'navyBlue'); }); $zinc->bind('buttonAB', '<1>', sub {&ButtonAB();}); $zinc->bind('buttonAC', '<1>', sub {&ButtonAC();}); $zinc->bind('buttonAD', '<1>', sub {&ButtonAD();}); $zinc->bind('buttonAE', '<1>', sub{exit;}); $mw -> bind('<Key-Escape>' => sub{exit;}); }