HQ220
HQ220

Reputation: 43

Pygame Text variable NOT Displaying TypeError: text must be a unicode or bytes

While I was trying to start making a Bitcoin mining incremental, I came across this error. I typed "text = font.render(Bitcoins, True, (0, 128, 0))" Bitcoins is my variable. It will not let me type in a variable, but there is no error when I try to type in "plan text". It will allow me to type in plain text, but it will display an error message when I type in a variable.

Please keep in mind that I do not have much experience in PyGame. - Thanks

    import pygame

pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
done = False

#This is the number of Bitcoins
Bitcoins = 0

font = pygame.font.SysFont("comicsansms", 72)

text = font.render(Bitcoins, True, (0, 128, 0))

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            done = True

    screen.fill((200, 160, 69))
    screen.blit(text,
        (320 - text.get_width() // 2, 240 - text.get_height() // 2))

    pygame.display.flip()
    clock.tick(60)

Upvotes: 2

Views: 121

Answers (1)

The Big Kahuna
The Big Kahuna

Reputation: 2110

That it is because Bitcoins needs to be a string but it is an int

text = font.render(str(Bitcoins), True, (0, 128, 0))

Upvotes: 3

Related Questions