파이 게임을 사용하고 있고 sys.exit()
을 사용할 때 문제가 발생합니다. 코드는 다음과 같습니다.파이 게임에서 sys.exit() 문제
import pygame, sys,os
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((468, 60))
pygame.display.set_caption('Game')
screen = pygame.display.get_surface()
file_name = os.path.join("data","image.bmp")
surface = pygame.image.load(file_name)
screen.blit(surface, (0,0))
pygame.display.flip()
def input(events):
for event in events:
if event.type == QUIT:
sys.exit(0)
else:
print event
while True:
input(pygame.event.get())
정말 파이 게임 튜토리얼의 코드입니다. sys.exit()
에 어떤 이벤트를 사용하든 관계없이 실제로 종료하려고하면 문제가 발생합니다.
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/pygame/examples/test.py", line 25, in <module>
input(pygame.event.get())
File "C:/Python27/Lib/site-packages/pygame/examples/test.py", line 20, in input
sys.exit(0)
SystemExit: 0
... 그리고 프로그램이 종료되지 않습니다. 여기서 내가 뭘 잘못하고 있니? 왜냐하면이 코드는 구식 버전의 Python 용이었습니다.
* 또한 당신이 아니라는 것을 나에게 보인다 * : 아니, 그는 pygame.locals를 가져 오니,'event.type == QUIT'은 완전히 괜찮습니다. 그러나 주 루프를 먼저 종료해야한다는 귀하의 대답은 정확합니다. – sloth
어떻게 든 그것을 놓쳤습니다 ..;) 감사합니다. – iKlsR
이것은 내가 두통을 많이 저지른 파이 게임을 배울 때의 대답입니다. – neuronet