pygame gui buttons

Solutions on MaxInterview for pygame gui buttons by the best coders in the world

showing results for - "pygame gui buttons"
Martina
12 Feb 2020
1 import pygame
2 import pygame_gui
3
4
5 pygame.init()
6
7 pygame.display.set_caption('Quick Start')
8 window_surface = pygame.display.set_mode((800, 600))
9
10 background = pygame.Surface((800, 600))
11 background.fill(pygame.Color('#000000'))
12
13 manager = pygame_gui.UIManager((800, 600))
14
15 hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 275), (100, 50)),
16                                             text='Say Hello',
17                                             manager=manager)
18
19 clock = pygame.time.Clock()
20 is_running = True
21
22 while is_running:
23     time_delta = clock.tick(60)/1000.0
24     for event in pygame.event.get():
25         if event.type == pygame.QUIT:
26             is_running = False
27
28         if event.type == pygame.USEREVENT:
29             if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
30                 if event.ui_element == hello_button:
31                     print('Hello World!')
32
33         manager.process_events(event)
34
35     manager.update(time_delta)
36
37     window_surface.blit(background, (0, 0))
38     manager.draw_ui(window_surface)
39
40     pygame.display.update()
41