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
suivant
Slide 1: Diapositive
ProgrammingHigher Education (degree)

Cette leçon contient 10 diapositives, avec diapositives de texte.

Éléments de cette leçon

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

Slide 1 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

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 - Diapositive

Slide 10 - Diapositive