Pygame screen freezes when I close it

前端 未结 4 1637
Happy的楠姐
Happy的楠姐 2021-01-21 01:19

The code loads up a pygame screen window, but when I click the X to close it, it becomes unresponsive. I\'m running on a 64-bit system, using a 32-bit python and 32-bit pygame.<

4条回答
  •  爱一瞬间的悲伤
    2021-01-21 01:26

    This is a pretty simple issue, you need to handle the "QUIT" event, see the event documentation at: http://www.pygame.org/docs/ref/event.html

    EDIT: It occurs to me now that you might be handling the "QUIT" event and its not working but without more details to your code I dunno.

    A quick example of a simple way to handle the "QUIT" event:

    import sys
    import pygame
    
    # Initialize pygame
    pygame.init()
    pygame.display.set_mode(resolution=(640, 480))
    
    # Simple(ugly) main loop
    curEvent = pygame.event.poll()
    
    while curEvent.type != pygame.QUIT:
          # do something
          curEvent = pygame.event.poll()
    

提交回复
热议问题