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
#exitwhen esc is pressed
foreventin pygame.event.get():
ifevent.type == QUIT:
return
elif event.type == KEYDOWN:
ifevent.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 codeevent = pygame.event.wait ()
ifevent.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"