I have implemented text box code to my simulation but now it is not rendering the main code, or rendering on top of my main code so nothing is displayed but the box :(
Here is my text box code :
def textbox(font20):
input_box = pygame.Rect(300,225,400,100)
color_inactive =(TURQUOISE)
color_active = (0,255,249)
color = color_inactive
active = False
text = ""
done = False
font = font20
while not done:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if input_box.collidepoint(event.pos):
active = not active
else:
active = False
color = color_active if active else color_inactive
if event.type == pygame.KEYDOWN:
if active:
if event.key == pygame.K_RETURN:
print(text)
text = ""
done = True
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
# Render the current text.
text_surface = font.render(text, True, color)
# Resize the box if the text is too long.
width = max(200, text_surface.get_width()+10)
input_box.w = width
# Blit the text.
screen.blit(text_surface, (input_box.x+5, input_box.y+5))
# Blit the input_box rect.
pygame.draw.rect(screen, color, input_box, 2)
pygame.display.flip()
I also screen.blit
to turquoise at the bottom where I draw the screen and flip it.