How do you display the text?
When I checked a simple sample of pygame, it was implemented by erasing it with a specific color (white) and redrawing it every time it was printed out, so I think I can hide it using isTextView at the time of redrawing.
The example below is an example of showing/hiding text every time you click.
import pygame
pygame.init()
WHITE = (255, 255, 255)
RED = (255, 0, 0)
screen = pygame.display.set_mode([200, 100])
done = False
clock = pygame.time.Clock()
isTextView = True;
font = pygame.font.Font(None, 32) #FontSetting
txt_surface = font.render ("This is Text", True, RED) #Text
while not done:
clock.tick(10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
If event.type == pygame.MOUSEBUTTONDOWN: # MouseClick Event
isTextView = not isTextView;
screen.fill(WHITE) #Fill the screen
ifisTextView: # whether text is displayed
screen.blit(txt_surface,(10, 10)) #text output
pygame.display.flip()
pygame.quit()
If the implementation method is different and the above content cannot be resolved, please attach a simple code.
Thank you.
© 2024 OneMinuteCode. All rights reserved.