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

1.9. The Anatomy of an Event Loop

When you are programming an application that uses a graphical interface rather than a textual interface, there are a lot of different things to consider. In a text-based application, you can read from standard input (STDIN), use command-line options, read files, or prompt the user for specific information. The keyboard is your only avenue of input from the user. In a GUI, input can not only come from those places, but it can also come from the mouse and the window manager (such as a "close" directive from a window manager like mwm or MS Windows). Although this extra input allows more flexibility in our applications, it also makes our job more difficult. As long as we tell it what to do, Perl/Tk helps us handle all that extra input gracefully.

Input in a GUI is defined by events. Events are typically different combinations of using the keyboard and mouse at the same or different times. If the user pushes the left mouse button on button "B", that is one type of event. Pushing the right mouse button on button "C" would be another event. Typing the letter "a" would be another event. Yet another event would be holding down the Control key and clicking with the middle mouse button. You get the idea.

Events are processed during an event loop. This event loop does just what its name says—it handles events during a loop. It determines what subroutines to call based on what type of event happened. Here is a pseudo-code event loop:

while (1) { get_event_info ...
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