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;

In reply to Re: Re: Re: Moving the mousepointer in Perl/Tk by kschwab
in thread Moving the mousepointer in Perl/Tk by Jouke

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.