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;}); }

In reply to TkZinc Can you Bind an array of buttons. by john.tm

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.