make sure your pygame.quit() is outside the event loop and inside the while loop, otherwise any action will cause the window to close. Hope this helps!