Closed Aston7292 closed 6 months ago
Hello!
This is expected behavior. By default all events are enabled. You need to explicitly block events.
I have updated your code to make it work as you expect it to:
import pygame as pg
pg.display.init()
pg.event.set_blocked(None)
pg.event.set_allowed(pg.QUIT)
win = pg.display.set_mode((800, 800))
while True:
for event in pg.event.get():
print(event)
if event.type == pg.QUIT:
exit()
pg.display.update()
The main difference here is the call to pg.event.set_blocked(None)
before doing pg.event.set_allowed(pg.QUIT)
. The former blocks all events, and then the latter unblocks quit specifically.
Even after using pygame.event.set_allowed all events will appear in the queue.