Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata