pygame library code example
Example 1: install pygame
pip install pygame
py -m pygame.examples.aliens
Example 2: python pygame
import pygame
import sys
pygame.init()
frames_per_second = 30
window_height = 600
window_width = 400
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
display = pygame.display.set_mode((window_width, window_height))
clock = pygame.time.Clock()
while True:
clock.tick(frames_per_second)
display.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
Example 3: pygame
Pygame is a good choice for creating GUI and game dev.
Install:
Windows:
pip install pygame
Example 4: pygame
1
2
3
4import pygame
5pygame.init()
6
7
8screen = pygame.display.set_mode([500, 500])
9
10
11running = True
12while running:
13
14
15 for event in pygame.event.get():
16 if event.type == pygame.QUIT:
17 running = False
18
19
20 screen.fill((255, 255, 255))
21
22
23 pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
24
25
26 pygame.display.flip()
27
28
29pygame.quit()
Example 5: pygame
python3 -m pip install -U pygame --user
Example 6: pygame
pip install pygame
And import the library.
import pygame