# Pygame - Text Input & Text Input Box import pygame import sys pygame.init() display = pygame.display.set_mode((400,300)) background = pygame.Surface((400, 300)) font = pygame.font.SysFont("Verdana",20) text_value = "" text = font.render(text_value,True,(255, 255, 255)) while True: mouse_pos = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_BACKSPACE: text_value = text_value [:-1] text = font.render(text_value, True, (255, 255, 255)) if event.key == pygame.K_RETURN: print(text_value) if event.type == pygame.TEXTINPUT: text_value += event.text text = font.render(text_value, True,(255,255,255)) display.fill((0,0,0)) display.blit(text,(100, 150)) pygame.display.update()