-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpygame_test.py
More file actions
57 lines (41 loc) · 1.45 KB
/
pygame_test.py
File metadata and controls
57 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pygame
pygame.font.init()
#pygame.font.get_init()
# create the display surface
display_surface = pygame.display.set_mode((500, 500))
# change the window screen title
pygame.display.set_caption('Our Text')
# Create a font file by passing font file
# and size of the font
font1 = pygame.font.SysFont('freesanbold.ttf', 50)
font2 = pygame.font.SysFont('chalkduster.ttf', 40)
# Render the texts that you want to display
text1 = font1.render('Hello!', True, (0, 255, 0))
text2 = font2.render('My Pygame text', True, (0, 255, 0))
# create a rectangular object for the
# text surface object
textRect1 = text1.get_rect()
textRect2 = text2.get_rect()
# setting center for the first text
textRect1.center = (250, 250)
# setting center for the second text
textRect2.center = (250, 300)
while True:
# add background color using RGB values
display_surface.fill((255, 0, 0))
# copying the text surface objects
# to the display surface objects
# at the center coordinate.
display_surface.blit(text1, textRect1)
display_surface.blit(text2, textRect2)
# iterate over the list of Event objects
# that was returned by pygame.event.get()
# method.
for event in pygame.event.get():
if event.type == pygame.QUIT:
# deactivating the pygame library
pygame.quit()
# quitting the program.
quit()
# update the display
pygame.display.update()