Python Forum
[PyGame] PyGame does not close when I press the close button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] PyGame does not close when I press the close button
#1
# 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.
Reply


Messages In This Thread
PyGame does not close when I press the close button - by Midnight_Sparkle3344 - May-25-2018, 03:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cant make a door automatically close a few seconds after i open it in pygame cooImanreebro 2 2,338 Dec-15-2020, 08:40 PM
Last Post: michael1789
  PyGame: detecting key press, but not key qrani 2 4,095 Sep-28-2018, 11:08 PM
Last Post: qrani

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020