Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main_screen():
- # Create input rectangles
- range_max_input_rect = pygame.Rect(280, 375, 50, 30)
- answer_input_rect = pygame.Rect(280, 435, 50, 30)
- input_font = pygame.font.Font('PKMN RBYGSC.ttf', 20)
- active_rect = None
- user_inputs = ["", ""]
- # Define necessary text
- texts = [
- main_font.render('Wheel Of Monotony', True, pygame.Color('black')),
- description_font.render("In the box below, please enter what you would like", True, pygame.Color('black')),
- description_font.render("the max. of the range you have to guess to be:", True, pygame.Color('black')),
- description_font.render("In the box below, please enter what you would think", True, pygame.Color('black')),
- description_font.render("the number I'm thinking of is: ", True, pygame.Color('black'))
- ]
- colors = {
- range_max_input_rect: (pygame.Color('black'), pygame.Color('white')),
- answer_input_rect: (pygame.Color('black'), pygame.Color('white'))
- }
- while True:
- screen.blit(background_image, [0, 0]) # Background
- for i, text in enumerate(texts):
- screen.blit(text, (75, 200 + 75 * i)) # Text showing
- for event in pygame.event.get(): # Event handling
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if event.type == pygame.MOUSEBUTTONDOWN:
- for rect in colors.keys():
- if rect.collidepoint(event.pos):
- active_rect = rect
- else:
- active_rect = None
- if event.type == pygame.KEYDOWN and active_rect:
- if event.key == pygame.K_BACKSPACE:
- user_inputs[active_rect] = user_inputs[active_rect][:-1]
- else:
- user_inputs[active_rect] += event.unicode
- for rect, color in colors.items(): # Draw rectangles
- active_color, passive_color = color
- color_for_rect = active_color if rect == active_rect else passive_color
- pygame.draw.rect(screen, color_for_rect, rect)
- for i, (rect, _) in enumerate(colors.items()): # Draw text
- text_surface = input_font.render(user_inputs[i], True, pygame.Color('white'))
- screen.blit(text_surface, (rect.x + 18, rect.y + 5))
- pygame.display.flip()
- clock.tick(60)
- return user_inputs[0], user_inputs[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement