-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_pygamegui.py
64 lines (42 loc) · 1.4 KB
/
test_pygamegui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# /// script
# dependencies = [
# "pygame-ce",
# "pygame-gui",
# "python-i18n",
# ]
# ///
import pygame
import pygame_gui
import i18n
pygame.init()
pygame.display.set_caption('Quick Start')
window_surface = pygame.display.set_mode((800, 600))
background = pygame.Surface((800, 600))
background.fill(pygame.Color('#000000'))
manager = pygame_gui.UIManager((800, 600))
class Window(pygame_gui.elements.UIWindow):
def __init__(self,
rect: pygame.Rect,
camera_name,
ui_manager: pygame_gui.core.interfaces.IUIManagerInterface):
super().__init__(rect, ui_manager, window_display_title=camera_name, resizable=True)
def update(self, time_delta: float):
super().update(time_delta)
async def main():
clock = pygame.time.Clock()
is_running = True
window_rect = pygame.Rect(0, 0, 400, 300)
window_rect.topleft = [10,10]
Window(window_rect, "Untitled pygame-gui window that can move", manager)
while is_running:
time_delta = clock.tick(60)/1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.flip()
await asyncio.sleep(0)
asyncio.run(main())