PYTHON Trouble Using Escape Key To Exit
I'm having trouble with the following code. It seems to respond to the escape key but it freezes really bad. I'm using pyscripter with python 2.7 and pygame. # An example implement
Solution 1:
I just modified the code like so, thanks giantenigma
#exit when esc is pressed
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
return
Solution 2:
Make sure that you call pygame.quit()
before you exit your main function.
running = True
while running:
# other code
event = pygame.event.wait ()
if event.type == pygame.QUIT:
running = False # Be interpreter friendly
pygame.quit()
Another possible solution would be to try running the program straight from the command line.
Post a Comment for "PYTHON Trouble Using Escape Key To Exit"