다음 코드를 권장합니다. 첫째, 그것은 Clock을 포함하므로 프로그램은 아무것도하지 않고 이벤트를 폴링하는 CPU를 먹지 않습니다. 둘째, pygame.quit()를 호출하여 Windows에서 IDLE로 실행할 때 프로그램이 멈추는 것을 방지합니다.
# Sample Python/Pygame Programs
# Simpson College Computer Science
# http://cs.simpson.edu/?q=python_pygame_examples
import pygame
# Define some colors
black = ( 0, 0, 0)
white = (255, 255, 255)
green = ( 0, 255, 0)
red = (255, 0, 0)
pygame.init()
# Set the height and width of the screen
size=[700,500]
screen=pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
#Loop until the user clicks the close button.
done=False
# Used to manage how fast the screen updates
clock=pygame.time.Clock()
# -------- Main Program Loop -----------
while done==False:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
# Set the screen background
screen.fill(black)
# Limit to 20 frames per second
clock.tick(20)
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Be IDLE friendly. If you forget this line, the program will 'hang'
# on exit.
pygame.quit()
이 방법이 가장 효과적입니다. 일단 완료되면 모든 상태를 쉽게 저장할 수 있습니다. – ninMonkey