in reply to Tk and mouse position
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Tk and mouse position
by Popcorn Dave (Abbot) on May 02, 2002 at 19:36 UTC |