/* jquery */ /* jquery accordion style*/ /* jquery init */

Learn Python - GUI Event Handling

Event handling is a critical aspect of GUI app development. Events can be generated in various ways, keyboard and mouse interaction being two obvious examples.

A GUI program must be able to determine which key was pressed. Not just the alphanumeric keys, but also shift keys, control keys, alt keys, function keys, cursor keys, the escape key and special keys like the Windows key.

As for the mouse, a program needs to determine the current coordinates of the mouse pointer, whether a mouse button has been clicked and if the scroll wheel has moved.

How do we do this? In a GUI program it's done with something called 'callbacks'. A callback is registered against a particular widget, and associated with a specific function. When an event occurs in the widget's window area, the function is called. This function can then analyse the event type and respond appropriately.

Once again all this functionality is contained within the tkinter module, so creating a GUI callback is a straightforward operation.

A post from my Learn Python on the Raspberry Pi tutorial.