Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Tk - finding what's being pointed at

by kevbot (Priest)
on Nov 26, 2016 at 07:38 UTC ( #1176585=note: print w/replies, xml ) Need Help??


in reply to Tk - finding what's being pointed at

Hello Chuma,

I was able to find a solution with some help from Re: Determine canvas object under click (Tk), and Mastering Perl Tk Chapter 9.6 - Creating Items in a Canvas - The Widget Item.

#!/usr/bin/env perl use strict; use warnings; use feature qw/say/; use Tk; #create a couple of arbitrary widgets my $main = MainWindow->new; my $can = $main->Canvas(-width => 600, -height => 400)->pack; my $lab = $can->Label(-text => "AAAAAAAA"); my $but = $can->Button(-text => "BBBBBBBB"); # The Label and Button methods used above do not have a '-tags' option +. So as # suggested by Mastering Perl/Tk, the createWindow method can be used +to add # tags $can->createWindow(100, 100, -window => $lab, -tags => ['MyLabel']); $can->createWindow(300, 150, -window => $but, -tags => ['MyButton']); # use a key binding to invoke an event $main->bind('<KeyPress-a>',sub{ # The method used below was shown in: # http://www.perlmonks.org/?node_id=987386 $can->addtag( qw/current closest/, $Tk::event->x, $Tk::event->y ); my @tags = grep {$_ ne 'current'} $can->gettags(qw/current/); $can->dtag(qw/current current/); say @tags; }); MainLoop;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1176585]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2017-12-13 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (378 votes). Check out past polls.

    Notices?