1# Be sure to install pygame via pip
2
3import pygame
4import sys
5
6# initialize it
7pygame.init()
8
9# configurations
10frames_per_second = 30
11window_height = 600
12window_width = 400
13
14# colors
15WHITE = (255, 255, 255)
16BLACK = (0, 0, 0)
17BLUE = (0, 0, 255)
18
19# creating window
20display = pygame.display.set_mode((window_width, window_height))
21
22# creating our frame regulator
23clock = pygame.time.Clock()
24
25# forever loop
26while True:
27 # frame clock ticking
28 clock.tick(frames_per_second)
29
30 # frame Drawing
31 display.fill(WHITE)
32
33 # event loop
34 for event in pygame.event.get():
35 if event.type == pygame.QUIT:
36 pygame.quit()
37 sys.exit()
38
1# Pygame boiler plate
2# Should have a red square on screen if run
3# pip3 install pygame
4
5import pygame
6
7screen = pygame.display.set_mode((1280, 720))
8
9running = True
10while running:
11 screen.fill((0, 0, 0))
12
13 for event in pygame.event.get():
14 if event.type == pygame.QUIT:
15 running = False
16
17 pygame.draw.rect(screen, (255, 0, 0), ((10, 10), (50, 50)))
18
19 pygame.display.update()
20
21pygame.quit()
22
1import sys
2import pygame
3
4pygame.init()
5
6screen = pygame.display.set_mode((800, 400))
7pygame.display.set_caption('Amogus Adventures')
8clock = pygame.time.Clock()
9
10test_font = pygame.font.Font('Graphics/Pixeltype.ttf', 50)
11StartButton = pygame.image.load('Graphics/STARTAS.png')
12GameStart = pygame.image.load('Graphics/gamestart.png')
13text_surface = test_font.render('Press enter to play!', True, 'Green')
14StartButton2 = pygame.image.load('Graphics/STARTAS2.png')
15class Game:
16 def __init__(self):
17 self.screen = pygame.display.set_mode((800, 400))
18 self.position = (100, 70)
19 self.size = (325,125)
20 self.rect = pygame.Rect(self.position, self.size)
21 self.color = pygame.Color("red")
22 pygame.display.set_caption('Amogus Adventures')
23
24 def run(self):
25 FPS = 60
26 clock = pygame.time.Clock()
27
28 while True:
29 for event in pygame.event.get():
30 if event.type == pygame.QUIT:
31 pygame.quit()
32 sys.exit()
33
34 mouse_position = pygame.mouse.get_pos()
35 left_button,_,_ = pygame.mouse.get_pressed()
36 if self.rect.collidepoint(mouse_position) and left_button:
37 # Clicked, do your code, start your game
38 print('clicked')
39
40 pygame.draw.rect(self.screen, pygame.Color("green"), self.rect)
41 else:
42 # Not clicked, do normal stuff
43 pygame.draw.rect(self.screen, pygame.Color("red"), self.rect)
44
45 clock.tick(FPS)
46 pygame.display.update()
47
48 screen.blit(GameStart,(0,0))
49 screen.blit(StartButton,(0,0))
50 screen.blit(text_surface,(115,25))
51
52if __name__ == '__main__':
53 pygame.init()
54 Game().run()
1Pygame is a good choice for creating GUI and game dev.
2Install:
3Windows:
4pip install pygame
1 1# Simple pygame program
2 2
3 3# Import and initialize the pygame library
4 4import pygame
5 5pygame.init()
6 6
7 7# Set up the drawing window
8 8screen = pygame.display.set_mode([500, 500])
9 9
1010# Run until the user asks to quit
1111running = True
1212while 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.
2929pygame.quit()
30