-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopwatch.py
More file actions
58 lines (49 loc) · 1.67 KB
/
Stopwatch.py
File metadata and controls
58 lines (49 loc) · 1.67 KB
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
import PySimpleGUI as sg
from time import time
def create_window():
sg.theme('black')
layout = [
#[sg.Push(), sg.Image(''), pad=0, enable_events = True,key='x'],
[sg.VPush()],
[sg.Text('', font = 'Young 50', key='Time')],
[sg.Button('Start', button_color = ('#FFFFFF', '#FF0000'), border_width=0, key='S'), sg.Button('Lap', button_color = ('#FFFFFF', '#FF0000'), border_width=0, key='L', visible = False)],
[sg.Column([[]], key = 'LAPS')],
[sg.VPush()]
]
return sg.Window(
'Stopwatch',
layout,
size = (300, 300),
no_titlebar = True,
element_justification = 'center')
window = create_window()
start_time = 0
active = False
lap_amount = 1
while True:
event, values = window.read(timeout = 10)
if event == sg.WIN_CLOSED:
break
if event == 'S':
if active:
active = False
window['S'].update('Reset')
window['L'].update(visible = False)
else:
if start_time > 0:
window.close()
window = create_window()
start_time = 0
lap_amount = 1
else:
start_time = time()
active = True
window['S'].update('Stop')
window['L'].update(visible = True)
if active:
elapsed_time = round(time() - start_time, 1)
window['Time'].update(elapsed_time)
if event == 'L':
window.extend_layout(window['LAPS'], [[sg.Text(lap_amount), sg.VSeperator(), sg.Text(elapsed_time)]])
lap_amount += 1
window.close()