1

When I run my program the pygame window opens and then it closes in my code I have only set the window size and the name so I don´t know why this is happening

import pygame
pygame.init()
win = pygame.display.set_mode([500, 500])
pygame.display.set_caption("First Game")`
John Gordon
  • 29,573
  • 7
  • 33
  • 58

1 Answers1

2

It seem like you dont have a game loop, the window open then close immediatly because there is not an event loop to keep the game running, here is a simple example that will keep the window open:

import pygame

pygame.init()

win = pygame.display.set_mode([500, 500])
pygame.display.set_caption("First Game")

run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    
    pygame.display.update()

pygame.quit()
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32