0

I'm trying to make a snake game with pygame using this tutorial. I've only gotten to the 11:43 mark. When I run my code, the game screen won't' stay open. What am I doing wrong?

Just an FYI: I'm using Visual studio code and have python 3.9 (I'm not sure if that will make a difference/be helpful)

import pygame from pygame.locals import *

if __name__ == "__main__": 
    pygame.init()
    surface = pygame.display.set_mode((500, 500))
    
    surface.fill(255, 255, 255)
    pygame.display.flip()
    
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == KEYDOWN: #Keydown
                pass
            elif event.type == QUIT:
                running = False

The screen pops up and stays up when I take out "surface.fill(255, 255, 255)" but I would like to have the background a different color. There is a comment saying that I should put the following: if name == "main": that was a mistake on my part. I did originally write that in my code but I think it didn't copy when I pasted it in here.

0 Answers0