Here's an example that keeps the pointer locked
inside a label widget. Hopefully this is closer
to what you were asking for. You'll have to fill
in getting the x/y coordinates for the event
from Tk::bind and
warping the pointer to a sensible spot
You may also want to have a look at Tk::grab.
You can maintain the focus for keyboard traversal
without confining the pointer, if this is useful.
Familiarize yourself with keyboard control
of focus before you run this :)
#!/usr/bin/perl
use Tk;
use strict;
my $m=Tk::MainWindow->new();
# create a big label so that the window is large
# enough to demonstrate this
my $label=$m->Label(-bd => 5, -relief => "ridge",
-text => "Label Text Here\n" x 10)->pack();
#
# bind Leave events from the label to
# generate a useless virtual
# event.
# (We don't really need to fire an event
# , we just need the warp option)
# Without the -x/-y options, it warps
# the pointer to the nw corner of the widget
#
$label->bind('<Leave>', sub {
my($w)=shift;
$w->eventGenerate('<<Not Used>>', -warp => 1);
}
);
MainLoop;
|