I'm trying to make my first graphical thing in Tk, but I'm having trouble getting a reference to what's under the mouse pointer. From what I gather, it seems like the easiest way should be $canvas->find('withtag','current'), but I can't get anything out of it. I've boiled it down to an example:
use feature(say); use Tk; #create a couple of arbitrary widgets $main=MainWindow->new; $can=$main->Canvas(-width => 600, -height => 400)->pack; $lab=$can->Label(-text => "AAAAAAAA")->place(-x=>100,-y=>100); $but=$can->Button(-text => "BBBBBBBB")->place(-x=>300,-y=>150); #use a key binding to invoke an event $main->bind('<KeyPress-a>',sub{ say $can->find('withtag','current'); #nothing! }); MainLoop;
I point at things and press "a", but apparently it's not finding anything - "say" just prints an empty line. I tried a few other things, for example the slightly more roundabout $can->find('closest',$can->pointerx,$can->pointery), which gives the same result.
Meanwhile, say $can->pointerx; works fine, so I guess I could implement my own search through the widgets, but that seems a little too roundabout for my taste.
What am I missing?
In reply to Tk - finding what's being pointed at by Chuma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |