python quit()讲解_Python:pygame.QUIT()

Just been messing around with pygame and ran into this error.

CODE:

import sys

import pygame

pygame.init()

size = width, height = 600, 400

screen = pygame.display.set_mode(size)

while 1:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit(); sys.exit();

ERROR:

Traceback (most recent call last):

File "C:/Users/Mike Stamets/Desktop/Mygame/Pygame practice/ScreenPractice.py", line 12, in

pygame.quit(); sys.exit();

SystemExit

I was just trying to set a while loop so that when the red X is pressed then the program will exit. What is going wrong?

解决方案

Toggle a bool when you hit escape. Then you can cleanly save data other in places, if needed.

done = False

while not done:

#events

for event in pygame.event.get():

if event.type == pygame.QUIT:

done = True

draw()


版权声明:本文为weixin_32927133原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。