Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

TkZinc Can you Bind an array of buttons.

by john.tm (Scribe)
on Oct 08, 2015 at 04:15 UTC ( #1144136=perlquestion: print w/replies, xml ) Need Help??
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;}); }

Replies are listed 'Best First'.
Re: TkZinc Can you Bind an array of buttons.
by Anonymous Monk on Oct 08, 2015 at 07:27 UTC

    Sure, you could simply loop  FunkyWonky( $_) for @array; where FunkyWonky sets up the onmouseover/onmouseout enter/leaver color changers

    See also commentary by zentara in GUIs in Tk.:Zinc; a perl module experiment

    After that see "testGraphics.pl" in zinc-demos (its "7. A set of demos based on Graphics.pm module (really better with openGL)." ... hippodrome tab)

    $zinc->bind('pushbtn', '<1>', sub {&pushButton $zinc->bind('pushbtn', '<ButtonRelease>', sub {&pullButton();});

    So tag each button with "pooshboton", then bind on pushboton + enter / leave ... see testGraphics.pl sub pushButton for details

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1144136]
Approved by marto
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-07-21 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (448 votes). Check out past polls.

    Notices?