Quick answer: Calling pygame.event.set_allowed([pygame.KEYDOWN]) blocks the window-close button? The whitelist is exclusive — QUIT events get filtered out too.
A perf-tuning experiment uses set_allowed to filter to keyboard events; clicking the X button does nothing because QUIT isn’t allowed.
Always Allow QUIT
pygame.event.set_allowed([pygame.KEYDOWN, pygame.KEYUP, pygame.QUIT])QUIT is the OS-driven close event. Drop it from the whitelist and the player can’t close the window.
Blocked Events Are Dropped
Blocked events never enter the queue. They’re not just hidden — they’re discarded. If you need them later, you must allow them and the queue resumes.
Use Filtering at Pump
For some workloads, leave all events allowed and filter in the dispatch loop. Costs a tiny CPU but no risk of dropping critical events.
Background Apps
FOCUS / WINDOW events also get dropped when blocked. If you handle pause-on-focus-lost, allow ACTIVEEVENT and the window-event family.
Verifying
Window close button works at all times. Set_allowed filters out high-volume events without breaking lifecycle.
“set_allowed is exclusive. Always include QUIT in the allow list.”
Default to never using set_allowed unless you measure event queue pressure — the surface area for bugs is large for a tiny perf win.