Pygame screen freezes when I close it

前端 未结 4 1635
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:52

    In using pygame, you have to handle all events including QUIT so if you don't handle the quit event, your program will not quit. Here's a code.

    import sys
    import pygame
    from pygame.locals import *
    
    def main():
        running = True
        while running:
            for event in pygame.event.get():
                if event.type==QUIT: #QUIT is defined at pygame.locals 
                    runnning = False
        #other game stuff to be done
    
    if __name__=='__main__':
        pygame.init()
        pygame.display.set_mode((640,480))
        main()
    

提交回复
热议问题