Advertisement
bitwise_gamgee

Untitled

Jun 8th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. def main_screen():
  2.     # Create input rectangles
  3.     range_max_input_rect = pygame.Rect(280, 375, 50, 30)
  4.     answer_input_rect = pygame.Rect(280, 435, 50, 30)
  5.     input_font = pygame.font.Font('PKMN RBYGSC.ttf', 20)
  6.     active_rect = None
  7.     user_inputs = ["", ""]
  8.  
  9.     # Define necessary text
  10.     texts = [
  11.         main_font.render('Wheel Of Monotony', True, pygame.Color('black')),
  12.         description_font.render("In the box below, please enter what you would like", True, pygame.Color('black')),
  13.         description_font.render("the max. of the range you have to guess to be:", True, pygame.Color('black')),
  14.         description_font.render("In the box below, please enter what you would think", True, pygame.Color('black')),
  15.         description_font.render("the number I'm thinking of is: ", True, pygame.Color('black'))
  16.     ]
  17.  
  18.     colors = {
  19.         range_max_input_rect: (pygame.Color('black'), pygame.Color('white')),
  20.         answer_input_rect: (pygame.Color('black'), pygame.Color('white'))
  21.     }
  22.  
  23.     while True:
  24.         screen.blit(background_image, [0, 0])  # Background
  25.  
  26.         for i, text in enumerate(texts):
  27.             screen.blit(text, (75, 200 + 75 * i))  # Text showing
  28.  
  29.         for event in pygame.event.get():  # Event handling
  30.             if event.type == pygame.QUIT:
  31.                 pygame.quit()
  32.                 sys.exit()
  33.  
  34.             if event.type == pygame.MOUSEBUTTONDOWN:
  35.                 for rect in colors.keys():
  36.                     if rect.collidepoint(event.pos):
  37.                         active_rect = rect
  38.                     else:
  39.                         active_rect = None
  40.  
  41.             if event.type == pygame.KEYDOWN and active_rect:
  42.                 if event.key == pygame.K_BACKSPACE:
  43.                     user_inputs[active_rect] = user_inputs[active_rect][:-1]
  44.                 else:
  45.                     user_inputs[active_rect] += event.unicode
  46.  
  47.         for rect, color in colors.items():  # Draw rectangles
  48.             active_color, passive_color = color
  49.             color_for_rect = active_color if rect == active_rect else passive_color
  50.             pygame.draw.rect(screen, color_for_rect, rect)
  51.  
  52.         for i, (rect, _) in enumerate(colors.items()):  # Draw text
  53.             text_surface = input_font.render(user_inputs[i], True, pygame.Color('white'))
  54.             screen.blit(text_surface, (rect.x + 18, rect.y + 5))
  55.  
  56.         pygame.display.flip()
  57.         clock.tick(60)
  58.  
  59.     return user_inputs[0], user_inputs[1]
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement