Tk runs by MainLoop; it only talks to your app via events. The trick is to bind some event to a subroutine in your app, and then access the coordinates you want (probably via the x and y methods, or possibly rootx and rooty methods, of the Tk::event object your receive).
#!/usr/local/bin/perl -w use strict; use Tk; my $mw = new Tk::MainWindow; my $c = $mw->Canvas->pack; my $tx = $c->createText(20, 10, -text => 'X: UNKNOWN'); my $ty = $c->createText(20, 25, -text => 'Y: UNKNOWN'); $c->Tk::bind('<Motion>' => [sub { my ($e,$x,$y) = (@_); $c->itemconfigure($tx, -text => "X: $x"); $c->itemconfigure($ty, -text => "Y: $y"); }, Ev('x'), Ev('y')]); MainLoop;
In reply to Re: Tk and mouse position
by ariels
in thread Tk and mouse position
by Popcorn Dave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |