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

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.