Event-driven programming

17-minute lesson · module-gui-03

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Event-driven programming

17-minute lesson · module-gui-03

  • Explain the event-driven model and the role of the event loop.
  • Attach a callback to a Button with the command argument.
  • Bind keyboard and mouse events to a handler with .bind().
  • Update a widget from inside a callback to respond to the user.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · GUI and Event Driven Programming / Command Events / Event Binding / Timer Events

Adaptation notes. Read-along lesson. tkinter needs a native window and a live event loop, which the Pyodide sandbox lacks, so there is no graded coding step. Code is for reading and local running. The click-counter example is ours; prose is original.

License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced.