Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def handle_events(rectangles):
- active_rect = None
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if event.type == pygame.MOUSEBUTTONDOWN:
- for rect in rectangles:
- 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:
- active_rect.user_input = active_rect.user_input[:-1]
- else:
- active_rect.user_input += event.unicode
- return active_rect
- def draw_rectangles(rectangles, active_rect):
- for rect in rectangles:
- color = rect.active_color if rect == active_rect else rect.passive_color
- pygame.draw.rect(screen, color, rect.rect)
- def draw_text(rectangles):
- for rect in rectangles:
- text_surface = rect.font.render(rect.user_input, True, pygame.Color('white'))
- screen.blit(text_surface, (rect.rect.x + 18, rect.rect.y + 5))
- class InputRectangle:
- def __init__(self, rect, font, active_color, passive_color):
- self.rect = rect
- self.font = font
- self.active_color = active_color
- self.passive_color = passive_color
- self.user_input = ""
- def main_screen():
- # Create input rectangles
- rectangles = [
- InputRectangle(pygame.Rect(280, 375, 50, 30), input_font, pygame.Color('black'), pygame.Color('white')),
- InputRectangle(pygame.Rect(280, 435, 50, 30), input_font, pygame.Color('black'), pygame.Color('white'))
- ]
- # 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'))
- ]
- while True:
- screen.blit(background_image, [0, 0]) # Background
- for i, text in enumerate(texts):
- screen.blit(text, (75, 200 + 75 * i)) # Text showing
- active_rect = handle_events(rectangles) # Event handling
- draw_rectangles(rectangles, active_rect) # Draw rectangles
- draw_text(rectangles) # Draw text
- pygame.display.flip()
- clock.tick(60)
- return [rect.user_input for rect in rectangles]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement