I am following Python Crash Course 2nd edition a the moment. I'm stuck on chapter 12 where you start with pygame. This is the code (from the book, so should work). I'm on mac using VSC.
import sys
import pygame
class AlienInvasion:
"""Overall class to manage game assets and behavior."""
def __init__(self):
"""Initialize the game, and create game resources"""
pygame.init()
self.screen = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alien Invasion")
# set the background color.
self.bg_color = (230, 230, 230)
def run_game(self):
"""Start th emain loop for the game"""
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
print('Quitting...')
sys.exit()
# Redraw the screen during each pass through the loop.
self.screen.fill(self.bg_color)
# Make the most recently drawn screen visible.
pygame.display.flip()
if __name__ == '__main__':
# Make a game instance and run the game.
ai = AlienInvasion()
print("running pygame...")
ai.run_game()
the print("running pygame...") statement runs, but no window opens.
Any ideas as to whats going wrong here?
EDIT: pygame is installed through pip3. I've tried running this code in Idle and VSC. The output to my terminal is as follows
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
running pygame...
no new window opens after that