-
Notifications
You must be signed in to change notification settings - Fork 43
/
pyinstaller_test.py
64 lines (44 loc) · 1.63 KB
/
pyinstaller_test.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
64
import os
import sys
import pygame
import pygame_gui
"""
TO build an executable run:
pip install pyinstaller
Then:
pyinstaller pyinstaller_specs/pyinstaller_build.spec
Or:
pyinstaller pyinstaller_specs/pyinstaller_onefile_build.spec
in the terminal.
"""
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller's 'onefile' mode """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
pygame.init()
pygame.display.set_caption('Quick Start')
window_surface = pygame.display.set_mode((800, 600))
manager = pygame_gui.UIManager((800, 600), resource_path('data/themes/pyinstaller_theme.json'))
background = pygame.Surface((800, 600))
background.fill(manager.ui_theme.get_colour('dark_bg'))
hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 280), (150, 40)),
text='Hello',
manager=manager)
clock = pygame.time.Clock()
is_running = True
while is_running:
time_delta = clock.tick(60) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
if event.type == pygame_gui.UI_BUTTON_PRESSED and event.ui_element == hello_button:
print('Hello World!')
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update()