0

I am coming back to pygame after around one and a half months of taking a break. I tried to open and create a window I tried to run it and the window immediately closed. This is all of the code:

import pygame
pygame.init()
screen_x = 230
screen_y = 230
display = pygame.display.set_mode ((screen_x, screen_y))

I am using VSCode if that does anything, this is the first time I have used VSCode so if I do not do something right I may not know.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128

1 Answers1

1

You need an event loop, or else the application will close immediately. Here is some starter code to do this:

import pygame


# screen object(width,height)
screen_x = 230
screen_y = 230
screen = pygame.display.set_mode((screen_x, screen_y))

# Set the caption of the screen
pygame.display.set_caption('Title')

# Variable to keep our game loop running
running = True

# game loop
while running:
    # for loop through the event queue
    for event in pygame.event.get():
        # Check for QUIT event  
        if event.type == pygame.QUIT:
                running = False

krmogi
  • 2,588
  • 1
  • 10
  • 26