Major update of all demo programs to use new PEP8 bindings, etc

This commit is contained in:
PySimpleGUI 2019-10-23 16:10:03 -04:00
parent 3f7c87c562
commit 7f52778bcc
307 changed files with 19546 additions and 3297 deletions

View file

@ -1,44 +1,41 @@
import PySimpleGUI as sg
import time
# form that doen't block
# good for applications with an loop that polls hardware
# Basic timer in PSG
def Timer():
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))
# Make a form, but don't use context manager
window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False)
# Create a text element that will be updated with status information on the GUI itself
# Create the rows
form_rows = [[sg.Text('')],
[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'))]]
# Layout the rows of the form and perform a read. Indicate the form is non-blocking!
window.Layout(form_rows)
#
# your program's main loop
sg.change_look_and_feel('Dark')
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)
i = 0
paused = False
start_time = int(round(time.time() * 100))
while (True):
while True:
# This is the code that reads and updates your window
button, values = window.read(timeout=0)
window.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
window['text'].update('{:02d}:{:02d}.{:02d}'.format(
(i // 100) // 60, (i // 100) % 60, i % 100))
if values is None or button == 'Exit':
break
if button == 'Reset':
i=0
i = 0
elif button == '-RUN-PAUSE-':
paused = not paused
window['-RUN-PAUSE-'].Update('Run' if paused else 'Pause')
window['-RUN-PAUSE-'].update('Run' if paused else 'Pause')
if not paused:
i += 1
# Broke out of main loop. Close the window.
window.close()
Timer()
Timer()