May-25-2018, 03:46 PM
# alien_invasion.py
import sys
import pygame
def run_game():
# Initialize game and create a screen object.
pygame.init()
screen = pygame.display.set_mode((800,400))
pygame.display.set_caption("Alien Invasion")
# Set the background color.
bg_color = (230, 230, 230)
# Start the main loop for the game.
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Redraw the screen during each pass through the loop.
screen.fill(bg_color)
# Make the most recently drown screen visible.
pygame.display.flip()
run_game()I am using Python 3.4.4 with the appropriate PyGame version. While this code runs, for some reason the application does not close. I have to close the IDLE shell itself in order to close the window. I'm not sure why the game doesn't close.
