- Event handlers (also called callbacks) are functions registered to an event such as a button click, keyboard press or mouse click.
- Event handlers react to the event by changing the state (collection of information) encoded in the program.
- Lecture examples - Events
- More examples - None
- Assignment to a variable inside a Python function creates a local variable.
- The scope of variable (portion of the program where the value of the variable can be accessed) is the body of function.
- Lecture examples - Local vs Global
- More examples - Example
- Variables defined outside functions are global variables. Their values may be accessed inside functions without declaration.
- To modify to a global variable inside a function, the variable must be declared inside the function using the keyword
global
. - Global variables are a convenient (but dangerous) way for event handlers to share information in event-driven programming.
- Lecture examples - Local vs Global
- More examples - Example
- Special module for CodeSkulptor that supports 2D interactive applications. The Docs button links to documentation for SimpleGUI.
- SimpleGUI allows creations of frames and timers as well as loading sounds and images.
- Frames include a control panel (with buttons and input fields), a status area (for monitoring keyboard and mouse events) and a canvas (with simple 2D drawing operations).
- Lecture examples - SimpleGUI, Template
- More examples - Layout, Frame, Errors
- Buttons may be created (and their event handlers registered) via
add_button
. - Buttons are positioned linearly (top/down) in the control panel in their order of creation.
- Lecture examples - Calculator, Buttons
- More examples - Structure, Canvas Color, Prize Boxes, True-False Quiz
- Input fields may be created (and their event handlers registered) via
add_input
. - Input fields are positioned linearly (top/down) in the control panel in their order of creation.
- The event handlers for the input field take a single parameter that is the text string entered.
- Lecture examples - Calculator, Input Fields
- More examples - Structure, Functions, Factoring, Silly Words
Programming Tips —
Week
2
from: https://class.coursera.org/interactivepython-005/wiki/view?page=week2