while running:
# HANDLE EVENT(S) #
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if input_box1.collidepoint(event.pos):
active1 = True
input_text1 = ''
active2 = False
active3 = False
elif input_box2.collidepoint(event.pos):
active2 = True
input_text2 = ''
active1 = False
active3 = False
elif input_box3.collidepoint(event.pos):
active3 = True
input_text3 = ''
active1 = False
active2 = False
else:
if active1:
input_text2 = str(round(int(input_text1)*6.746,2))
elif active2:
input_text1 = str(round(int(input_text2)/6.746,2))
elif active3:
input_text1 = str(round(int(input_text3)*21.12,2))
active1 = False
active2 = False
active3 = False
if event.type == pygame.KEYDOWN:
if active1:
if event.type == pygame.KEYDOWN:
if active1:
if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
active1 = False
input_text2 = str(round(int(input_text1)*6.746,2))
input_text3 = str(round(int(input_text1)*21.12,2))
elif event.key == pygame.K_BACKSPACE:
input_text1 = input_text1[:-1]
else:
input_text1 += event.unicode
elif active2:
if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
active2 = False
input_text1 = str(round(int(input_text2)/6.746,2))
input_text3 = str(round(int(input_text1)*21.12,2))
elif event.key == pygame.K_BACKSPACE:
input_text2 = input_text2[:-1]
else:
input_text2 += event.unicode
elif active3:
if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
active3 = False
input_text1 = str(round(int(input_text3)/21.12,2))
input_text2 = str(round(int(input_text1)/6.746,2))
elif event.key == pygame.K_BACKSPACE:
input_text3 = input_text3[:-1]
else:
input_text3 += event.unicode
# UPDATE DATA #
color1 = ACTIVE_COLOR if active1 else INACTIVE_COLOR
color2 = ACTIVE_COLOR if active2 else INACTIVE_COLOR
color2 = ACTIVE_COLOR if active3 else INACTIVE_COLOR
txt_surface1 = font.render(input_text1, True, color1)
txt_surface2 = font.render(input_text2, True, color2)
txt_surface3 = font.render(input_text3, True, color2)
# RENDER GRAPHICS #
screen.fill(BG_COLOR)
screen.blit(header_surface, header_rect)
screen.blit(input1_label_surface, input1_label_rect)
screen.blit(input2_label_surface, input2_label_rect)
screen.blit(input3_label_surface, input3_label_rect)
screen.blit(txt_surface1, (input_box1.x+5, input_box1.y+5))
screen.blit(txt_surface2, (input_box2.x+5, input_box2.y+5))
pygame.draw.rect(screen, color1, input_box1, 2)
pygame.draw.rect(screen, color2, input_box2, 2)
pygame.draw.rect(screen, color2, input_box3, 2)
pygame.display.flip()
pygame.quit()