import pygame, sys #General setup pygame.init() clock = pygame.time.Clock() #Display Surfaces / variables screen = pygame.display.set_mode((800,800)) base_font = pygame.font.Font(None,32) user_text = '' input_rect = pygame.Rect(200,200,140,32) colour_active = pygame.Color('aqua') colour_passive = pygame.Color('aquamarine4') colour = colour_passive active = False #Loop that is always true while True: for event in pygame.event.get(): #Closing the game if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if input_rect.collidepoint(event.pos): active = True else: active = False #User input if event.type == pygame.KEYDOWN: if active == True: if event.key == pygame.K_BACKSPACE: user_text = user_text[:-1] else: user_text += event.unicode #Changing colour of textboxes/text if active: colour = colour_active else: colour = colour_passive #Drawing (making code into visable image) screen.fill((0,0,0)) text_surface = base_font.render(user_text,True,(255,255,255)) screen.blit(text_surface,(input_rect.x+ 5,input_rect.y + 5)) pygame.draw.rect(screen,colour,input_rect,2) #Containing text into text box input_rect.w = max(100,text_surface.get_width() + 10) #Misc/framerate pygame.display.flip() clock.tick(60)