02-01 - Create Window

01

We use init(), set_mode to create the window,

pygame.init()
surface = pygame.display.set_mode((900,300))
pygame.display.flip()

flip() is needed to display it But

**NOTICE in the Video the screen appears briefly behind vs code and in front of the browser, AND IF IT DOESN'T WORK change python interpreter from 3.10.9, or back to 3.13 and (Install pygame in venv) if not working from default

import pygame

if __name__ == '__main__':
    pygame.init()
    surface = pygame.display.set_mode((900,300))
    pygame.display.flip()

02

import the time library and use sleep for 3 seconds

NOTICE how it now stays open for 2 seconds.

import pygame
import time

if __name__ == '__main__':
    pygame.init()
    surface = pygame.display.set_mode((900,300))
    pygame.display.flip()
    time.sleep(2)

03

Visit Pygame documentation https://www.pygame.org/docs/ for infomation on function, methods, flag ...

It's a little confusing, you have to dig around, review documentation on the the above

  • pygame.init()
  • pygame.display.set_mode
  • pygame.display.flip()

04

**warning error i received. DO NOT name script pygame.py