WK4:Event-Driven Programming and IDE Features (Session 1)

Welcome to Week 4
Event-Driven Programming and IDE Features
Module Lecturer: Dr Raghav Kovvuri
Email: raghav.kovvuri@ieg.ac.uk

1 / 10
volgende
Slide 1: Tekstslide
ProgrammingHigher Education (degree)

In deze les zitten 10 slides, met tekstslides.

Onderdelen in deze les

Welcome to Week 4
Event-Driven Programming and IDE Features
Module Lecturer: Dr Raghav Kovvuri
Email: raghav.kovvuri@ieg.ac.uk

Slide 1 - Tekstslide

Introduction
Definition: A programming paradigm where the flow of the program is determined by events
Events: User actions, sensor outputs, messages from other programs
Key Components
  • Event Sources (e.g., UI elements, timers, network)
  • Event Handlers (functions that respond to events)
  • Event Loop (main program loop that listens for events)
Contrast with Sequential Programming:
  • Sequential: Predetermined order of execution
  • Event-Driven: Reactive, based on external inputs

Slide 2 - Tekstslide

Advantages of EDP

Scalability
Responsiveness 

Modularity
Resource Efficiency

Real-world Modeling
  • Idle until events occur, conserving system resources
  • Well-suited for GUI applications and I/O-bound programs
  • Naturally models real-world interactions and processes
  • Intuitive for developing simulations and interactive systems



  • Quickly reacts to user inputs and system events
  • Enhances user experience in interactive applications
  • Easily handles multiple input sources
  • Adaptable to complex user interfaces and multi-threaded environments
  • Event handlers can be developed and maintained separately
  • Facilitates parallel development in large projects

Slide 3 - Tekstslide

Example (Python & Tkinter) (1) 
 Basic Event-Driven Programming
  • tk.Tk(): Creates the main window
  • tk.Button(): Creates a button widget
  • command=button_click: Associates the button click event with the handler
  • root.mainloop(): Starts the event loop 
Key Concept: The program waits for user interaction rather than executing sequentially

Slide 4 - Tekstslide

Objects as Event Handlers:
  • Methods of a class serve as event handlers
  • Encapsulates behavior associated with events
State Management:
  • Object's state can change in response to events
  • Provides a natural way to model complex systems
Example (Python & Tkinter) (2) 
Objects as Event Sources:
  • UI elements (buttons, text fields) as objects
  • Each object can generate specific events
Combining OOP and Event-Driven Concepts:
Benefits:
  • Improved code organization
  • Easier state management
  • Enhanced reusability and maintainability

Slide 5 - Tekstslide

Example: Simple Calculator GUI
  • Download WK4_EDP_Calculator.py from Canvas and try to understand the Code 
Key Points:
  • Class-based structure for organization
  • Event handlers (click method) respond to button presses
  • GUI layout managed within the class
Did you notice any issue with in the Output?

Slide 6 - Tekstslide

Hands on Exercise
Task: add a reset input button to the calculator. This button should clear the current input and reset the calculator to its initial state.
timer
30:00

Slide 7 - Tekstslide

IDE Features
Setup and learn basics of VS Code
Using extensions in VS Code
Debugging
Version Control in VS Code
Version Control in VS Code
Version Control in VS Code
Version Control in VS Code
Version Control in VS Code
For Introductory Videos Visit
timer
30:00

Slide 8 - Tekstslide

Conclusion
  • We've evolved our OOP calculator to use event-driven programming
  • Core OOP principles remain the same
  • Event-driven approach makes our program more interactive
  • This is how most modern GUI applications work! 
Additional Resources
Tkinter documentation: https://docs.python.org/3/library/tkinter.html
Real Python's Tkinter tutorial: https://realpython.com/python-gui-tkinter/
VS Code Python tutorial: https://code.visualstudio.com/docs/python/python-tutorial

Slide 9 - Tekstslide

Slide 10 - Tekstslide