Decoupling Complex Systems with Event-Driven Python Programming

What exactly is event-driven programming in Python Programming?

Event-driven != asynchronous

CREATE TRIGGER before_user_update 
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE PROCEDURE check_user();
CREATE TRIGGER after_user_update
AFTER UPDATE ON users
FOR EACH ROW
EXECUTE PROCEDURE log_user_update();

Event-driven programming in GUIs

import this 
from tkinter import *
from tkinter import messagebox
rot13 = str.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm"
)
def main_window(root: Tk):
frame = Frame(root)
frame.pack()
zen_button = Button(frame, text="Python Zen", command=show_zen)
zen_button.pack(side=LEFT)
def show_zen():
messagebox.showinfo("Zen of Python", this.s.translate(rot13))
if __name__ == "__main__":
root = Tk()
main_window(root)
root.mainloop()
The Tk library that powers the tkinter module is usually bundled with Python distributions. If it's somehow not available on your operating system you should be easily able to install it through your system package manager. For instance, on Debian-based Linux distributions, you can easily install it for Python as the python3-tk package using the following command: sudo apt-get install python3-tk
Button(frame, text="Python Zen", command=show_zen)

Event-driven communication

import this  from flask import Flask  app = Flask(__name__)  rot13 = str.maketrans( 
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm"
)
def simple_html(body):
return f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Book Example</title>
</head>
<body>
{body}
</body>
</html>
"""
@app.route('/')
def hello():
return simple_html("<a href=/zen>Python Zen</a>")
@app.route('/zen')
def zen():
return simple_html(
"<br>".join(this.s.translate(rot13).split("\n"))
)
if __name__ == '__main__':
app.run()

Summary of Python programming

--

--

--

Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Making Calculator App From Flutter.

Using Jira for Kanban: really?

Ordinal Differential Equation (ODE) in Python

This week in DevOps — Issue #10

Automate Cloud Run deployment in a minute

Increase and Decrease the size of Static Partition😎

How to Connect Google Drive to Python using PyDrive

Manual Pentest Reports Waste Your Time | Cyver.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ODSC - Open Data Science

ODSC - Open Data Science

Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.

More from Medium

Easily install Python using Pyenv on yoMacbook M1 (Apple Silicon)

M1 is slower and less efficient than 2014 Core i7 in pandas processing ?

How We Migrated from Python Multithreading to Asyncio

Ok. Lets talk about Python virtual environments.