Skip to content Skip to sidebar Skip to footer

Why Text Display For 2 Seconds In Pygame

Text wchich I display is displaying for only around 2 sec. I want that it will display while I click to other area elif msg[0:7] == 'YOU WIN' and Message_id == '200': print('Yo

Solution 1:

If you want something to be drawn permanently, you need to draw it in the application loop. The typical PyGame application loop has to:

Create the text surface at initialization:

winTextSurf = font.render('You Win', True, (0, 0, 0))
winTextRect = winTextSurf.get_rect(topleft = (600 // 2, 700 // 2)

Add a variable that indicates the text needs to be drawn:

drawWinText = Fasle

Set the variable if the text needs to be drawn:

elif msg[0:7] == 'YOU WIN'and Message_id == '200':
    drawWinText = Truebreak

When you no longer want the text to be drawn, you need to reset the value.

drawWinText = False

Draw the text in the main application loop depending on the status of drawWinText:

while run:

    # [...]if drawWinText:
        surface.blit(winTextSurf, winTextRect)

    pygame.display.flip()

See the answers to question Python - Pygame - rendering translucent text for how to draw transparent text.

Post a Comment for "Why Text Display For 2 Seconds In Pygame"