forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbig_button_gui.py
executable file
·50 lines (41 loc) · 1.43 KB
/
big_button_gui.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
import logging
from gi.repository import GLib
import guizero
import big_button_project
logger = logging.getLogger('BigButton')
loop = GLib.MainLoop()
def refresh_app():
score.set(big_game.score)
# print(big_game.btn_active)
if big_game.game_active:
button.set_text('Running...')
active.configure(background=big_game.btn_active)
else:
button.set_text('Start')
active.configure(background='lightgray')
app.update()
return True
def end_app():
logger.info('Game Exit!!!!')
big_game.game_exit()
app.destroy()
loop.quit()
if __name__ == '__main__':
logger.debug('Debug On!!!!')
app = guizero.App("Big Button Project",
layout='grid',
width='600',
height='300')
big_game = big_button_project.ButtonGame()
title = guizero.Text(app, text='Big Button Game', size=24, grid=[0, 1])
button = guizero.PushButton(app, big_game.game_start, text='Start', grid=[1, 1])
active = guizero.TextBox(app, text='', width=20, grid=[2, 1])
active.configure(background=big_game.btn_active)
score_lbl = guizero.Text(app, text='Score:', size=36, grid=[3, 0])
score = guizero.Text(app, text=big_game.score, size=36, grid=[3, 2])
game_over = guizero.PushButton(app, end_app, text='Exit', grid=[4, 1])
GLib.idle_add(refresh_app)
try:
loop.run()
except KeyboardInterrupt:
end_app()