When the X button is pressed, an event object is created and added to the event queue. The event objects are retrieved with pygame.event.get()
. The type
property indicates the type of the event.
If you do not check event.type == pygame.QUIT
and do not set run = False
, the loop will never end (endless loop), the application will never terminate and the window will not close.
pygame.quit()
deinitializes all pygame modules, which also deinitializes the display module and causes the window to close. The window is also closed when the application exits after your script is finished.