14.4. Event Information

You can find out information about an event by using the Ev method. There are many values you can use in a call to Ev, and they are thoroughly documented on the Perl/Tk documentation web site at http://w4.lns.cornell.edu/~pvhp/ptk/doc/bind.htm, which is maintained by Peter Prymmer, and http://www.perl.com/ptk/pod/bind.pod. I'll cover the values that you would want to use 99.9 percent of the time. Remember that certain values used with Ev are only valid for certain events. If you use an Ev value that doesn't apply, you'll get an undefined value.

14.4.1. Coordinates

To determine the coordinates at which the event happened, use Ev('x') and Ev('y'). They return coordinates relative to the window in which the event happened. If you want coordinates relative to the root of your window system (desktop in Windows, Xroot in X), use uppercase X and Y: Ev('X') and Ev('Y').

Ev('X') and Ev('Y')are valid only for ButtonPress, ButtonRelease, KeyPress, KeyRelease, or Motion events.

14.4.2. Button Number

To find out which button number on the mouse was pressed, use Ev('b'). It is valid only for ButtonPress or ButtonRelease events. If you use Ev('b') with a <Button-1> event, you would obviously get 1 back.

14.4.3. Height and Width

Use an 'h' to return the height and a 'w' to return the width associated with the event. The width and height returned indicate how large the widget is. For instance, if you want to find out the new size of a button after the window has been ...

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.