-1

I am watching a tutorial on pygame (made by Tech With Tim) and after following all the stuff with the run variable and the while run function, my window is still closing immediately. I have searched stackoverflow and the pygame forums but they all say stuff similar that doesn't work.

import pygame

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("First game")

BACKGROUND = (255, 255, 255)


def main():
    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
        WIN.fill(BACKGROUND)
        pygame.display.update()
    
    pygame.quit()


if __name__ == "__name__":
    main()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
RSMP
  • 1

1 Answers1

1

Replace

if __name__ == "__name__":

with

if __name__ == "__main__":
Michael Hodel
  • 2,845
  • 1
  • 5
  • 10