1import pygame
2pygame.init()
3window = pygame.display.set_mode((500, 500))
4
5def set_text(string, coordx, coordy, fontSize): #Function to set text
6
7 font = pygame.font.Font('freesansbold.ttf', fontSize)
8 #(0, 0, 0) is black, to make black text
9 text = font.render(string, True, (0, 0, 0))
10 textRect = text.get_rect()
11 textRect.center = (coordx, coordy)
12 return (text, textRect)
13
14window.fill((255, 255, 255)) #Fills the whole window with white
15#Places "Text in Pygame!" with an x,y coord of 250, 250 and 60 font size
16totalText = set_text("Text in Pygame!", 250, 250, 60)
17window.blit(totalText[0], totalText[1])
18pygame.display.update()