Cavan
Cavan

Reputation: 23

Text will not appear on the screen in pygame

This is the code i have used to try add text to the screen

font = pygame.font.Font('freesansbold.ttf', 20)

TextX = 700
TextY = 100

def showText(x,y):
    text = font.render("random text", True, (255,0,0))
    screen.blit(text, (x,y))

# Game Loop
running = True
while running:
    showText(TextX,TextY)

I am trying to add the writing in the space on the right, in a column preferable Can anyone tell me why the code is not allowing me to blit the text onto the screen and how i should change the code to allow it to blit more text onto the screen.

Upvotes: 2

Views: 43

Answers (1)

Daniel Giger
Daniel Giger

Reputation: 2533

You need to update the display with pygame.display.update(). To write text in a column, you can call your function in a loop. Here's an updated version of your loop that prints the text repeatedly in a column:

while running:
    window_height = pygame.display.get_surface().get_size()[1]
    for TextY in range(100, window_height, 100):
        showText(TextX,TextY)
    pygame.display.update()

Upvotes: 1

Related Questions