how to make a pygame window 1

how to make a pygame window

import pygame
background_colour = (255,255,255)
(width, height) = (300, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Tutorial 1')
running = True
while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False

Here is what the above code is Doing:
1. We import the pygame library.
2. We create a background colour.
3. We create a screen size.
4. We create a screen.
5. We give the screen a title.
6. We fill the screen with the background colour.
7. We update the screen.
8. We set running to True.
9. We start a while loop.
10. We get all the events.
11. If the event is equal to pygame.QUIT, we set running to False.
12. We close the while loop.
13. We close the program.

Similar Posts