Python:pygame.QUIT() [英] Python: pygame.QUIT()
本文介绍了Python:pygame.QUIT()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是在摆弄pygame并遇到了这个错误.
Just been messing around with pygame and ran into this error.
代码:
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();
错误:
Traceback (most recent call last):
File "C:/Users/Mike Stamets/Desktop/Mygame/Pygame practice/ScreenPractice.py", line 12, in <module>
pygame.quit(); sys.exit();
SystemExit
我只是试图设置一个while循环,以便当按下红色的X时程序将退出.怎么了?
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()
这篇关于Python:pygame.QUIT()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文