#text input to terminal import pygame import sys from pygame.locals import * pygame.init() DISPLAYWINDOWSIZE = pygame.display.set_mode((600, 400)) pygame.display.set_caption("Test") DISPLAYWINDOWSIZE.fill((255, 255, 255)) font = pygame.font.SysFont("Verdana", 20) text_value = "" text = font.render(text_value, True, (0, 0, 0)) # Changed text color to black running = True while running: for event in pygame.event.get(): if event.type == QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_BACKSPACE: text_value = text_value[:-1] elif event.key == pygame.K_RETURN: print(text_value) else: text_value += event.unicode # Render the text again only if it has changed new_text = font.render(text_value, True, (0, 0, 0)) if new_text != text: text = new_text DISPLAYWINDOWSIZE.fill((255, 255, 255)) # Clear the screen DISPLAYWINDOWSIZE.blit(text, (100, 150)) pygame.display.update() pygame.quit() sys.exit()