2018-09-04 23:47:14 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
import time
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# Basic timer in PSG
|
|
|
|
|
2018-09-04 23:47:14 +00:00
|
|
|
def Timer():
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Dark')
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.set_options(element_padding=(0, 0))
|
|
|
|
form_rows = [[sg.Text(size=(8, 2), font=('Helvetica', 20),
|
|
|
|
justification='center', key='text')],
|
|
|
|
[sg.Button('Pause', key='-RUN-PAUSE-'),
|
|
|
|
sg.Button('Reset'),
|
|
|
|
sg.Exit(button_color=('white', 'firebrick4'))]]
|
|
|
|
window = sg.Window('Running Timer', form_rows,
|
|
|
|
no_titlebar=True, auto_size_buttons=False)
|
2018-09-04 23:47:14 +00:00
|
|
|
i = 0
|
|
|
|
paused = False
|
2019-10-03 01:13:58 +00:00
|
|
|
start_time = int(round(time.time() * 100))
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
while True:
|
2018-09-04 23:47:14 +00:00
|
|
|
# This is the code that reads and updates your window
|
2019-10-03 01:13:58 +00:00
|
|
|
button, values = window.read(timeout=0)
|
2019-10-23 20:10:03 +00:00
|
|
|
window['text'].update('{:02d}:{:02d}.{:02d}'.format(
|
|
|
|
(i // 100) // 60, (i // 100) % 60, i % 100))
|
2018-09-04 23:47:14 +00:00
|
|
|
|
2018-09-07 14:33:23 +00:00
|
|
|
if values is None or button == 'Exit':
|
2018-09-04 23:47:14 +00:00
|
|
|
break
|
|
|
|
|
2019-06-26 15:09:42 +00:00
|
|
|
if button == 'Reset':
|
2019-10-23 20:10:03 +00:00
|
|
|
i = 0
|
|
|
|
|
2019-10-03 01:13:58 +00:00
|
|
|
elif button == '-RUN-PAUSE-':
|
2018-09-04 23:47:14 +00:00
|
|
|
paused = not paused
|
2019-10-23 20:10:03 +00:00
|
|
|
window['-RUN-PAUSE-'].update('Run' if paused else 'Pause')
|
2018-09-04 23:47:14 +00:00
|
|
|
|
|
|
|
if not paused:
|
|
|
|
i += 1
|
2019-10-03 01:13:58 +00:00
|
|
|
|
|
|
|
window.close()
|
2018-09-04 23:47:14 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
Timer()
|