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

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: # $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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1176585]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2018-09-22 11:08 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (190 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!