3

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('You Win')
    textSurface = font.render('You Win', True, (0, 0, 0))
    largeText = pygame.font.Font('freesansbold.ttf', 115)
    TextSurf = pygame.font.render('You Win', True, (0, 0, 0))
    TextRect = textSurface.get_rect()
    TextRect.center = ((600 / 2), (700 // 2))
    surface.blit(TextSurf, TextRect)
    grid.draw(surface)
    pygame.display.flip()
    break
  • Do you mean like a simple pop-up message that disappears after 2 seconds? Can you explain a bit more how the "click" in another area works with it? – Kingsley Jun 19 '20 at 02:44
  • Yes, like a pop-up but the background of the text is transparent. This is tic tac toe game. If I click in choosen area on the board display X or O. If I click of the bootom of window the player start the game – Kamil Stępniewski Jun 19 '20 at 06:51

1 Answers1

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 = True
    break

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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174