-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_txt.py
48 lines (36 loc) · 1.01 KB
/
test_txt.py
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
import pygame
import sys
# Initialize Pygame
pygame.init()
# Constants
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
FONT_SIZE = 36
# Create a window
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Text Printing in Pygame")
# Create a font object
font = pygame.font.Font(None, FONT_SIZE)
# Text to be displayed
text = "Hello, Pygame!"
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear the screen
screen.fill(WHITE)
# Render the text
text_surface = font.render(text, True, BLACK)
# Position the text
text_rect = text_surface.get_rect()
text_rect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
# Draw the text onto the screen
screen.blit(text_surface, text_rect)
# Update the display
pygame.display.flip()
# Quit Pygame
pygame.quit()
sys.exit()