1# To install pygame, type 'pip install pygame' in the
2# windows powershell or the os terminal
3
4# To create a blank screen as a setup for a game, use:
5import pygame
6import sys
7
8pygame.init()
9
10clock = pygame.time.Clock()
11
12FPS = 30 # How many times the screen will update per second
13
14screen_width = 600 # How wide the window will be
15screen_height = 600 # how high the window will be
16
17screen = pygame.display.set_mode((screen_width, screen_height)) # creates the screen
18
19while True:
20 clock.tick(FPS) # updates the screen, the amount of times it does so depends on the FPS
21 for event in pygame.event.get(): # Allows you to add various events
22 if event.type == pygame.QUIT: # Allows the user to exit using the X button
23 pygame.quit()
24 sys.exit()
25
26
27
28
29
30
1# Import and initialize the pygame library
2import pygame
3pygame.init()
4
5# Set up the drawing window
6screen = pygame.display.set_mode([500, 500])
7
8# Run until the user asks to quit
9running = True
10while running:
11
12 # Did the user click the window close button?
13 for event in pygame.event.get():
14 if event.type == pygame.QUIT:
15 running = False
16
17 # Fill the background with white
18 screen.fill((255, 255, 255))
19
20 # Draw a solid blue circle in the center
21 pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
22
23 # Flip the display
24 pygame.display.flip()
25
26# Time to end the Game
27pygame.quit()
28
1# Simple pygame program
2 2
3 3 # Import and initialize the pygame library
4 4 import pygame
5 5 pygame.init()
6 6
7 7 # Set up the drawing window
8 8 screen = pygame.display.set_mode([500, 500])
9 9
1010 # Run until the user asks to quit
1111 running = True
1212 while running:
1313
1414 # Did the user click the window close button?
1515 for event in pygame.event.get():
1616 if event.type == pygame.QUIT:
1717 running = False
1818
1919 # Fill the background with white
2020 screen.fill((255, 255, 255))
2121
2222 # Draw a solid blue circle in the center
2323 pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
2424
2525 # Flip the display
2626 pygame.display.flip()
2727
2828 # Done! Time to quit.
2929 pygame.quit()
1crashed = False
2
3while not crashed:
4
5 for event in pygame.event.get():
6 if event.type == pygame.QUIT:
7 crashed = True
8
9 print(event)
10
11 pygame.display.update()
12 clock.tick(60)