Week 2: Interactive Applications In Python Flashcards
Event-Dirven Programming Model?
Program Starts, initializes, and “waits” for something to happen - it does not require one specific thing to happen, but will react based on what does happen.
These “events” are executed by “handlers”.
The program ends when a “quit” event occurs.
The key difference is the event-driven programming model is centred on a default of waiting.
Types of Events in Event-Driven Programming model? (4)
Input (Button, Text box)
Keyboard (Key down, key up)
Mouse (Click, drag)
Timer (count up, countdown)
Event Queue?
When an event occurs in Python code, it goes into the event queue. The program looks to see what’s next in the queue and pairs it to the appropriate handler, then looks at the queue again so every event occurs in order.
Global vs Local Variables?
Global Variables take place outside of any functions and can be used by all of the functions. Local variables are created in, and used by, a single function.
Global variables can be modified in functions without affecting their values outside of the function Eg. changing the value in the function only
In a function, can modify a global variable by leading with the term “global, then the variable, and then the new definition.
Eg. global num
num = 5
What is a Handler?
A handler is a function that launches in response to an event and will run the expected outcome from the event,
What is the recommended Python program structure? (7 Steps)
Globals Helper Functions Classes Define Event Handlers Create a Frame Register Event Handlers Start Frame & Timers
In a Python GUI, when a user pushes a button, what argument is passed to the event handler?
Answer Nothing - there are no arguments passed to an event handler for a button;