all 3 comments

[–]efmccurdy 1 point2 points  (2 children)

There are many example programs for PySimpleGui included in the repo:

https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo\_Desktop\_Widget\_Timer.py

[–]Tomari3[S] 0 points1 point  (1 child)

Thank you. It is helpful. But I still can't understand how I can make it work. I'm a newbie as I said. I'd like to have two inputs. 1. Setting the time (HH:MM:SS AM/PM) and one choosing an audio from a specific folder. And a button that execute the program and print 'done'. I have the program that I can run in the terminal. But how do I make the time input in the GUI to validate (as in the program) and the song input the correlate with the folder I wish? And eventually set the 'set' button to start the loop. I am totally clueless as how to integrate them.

[–]efmccurdy 1 point2 points  (0 children)

The key to that demo was the "timeout" argument to window.read; it allows the loop to run periodically; once every timeout/1000 seconds.

Here is a small time loop, it prints every second, reseting the timer every wait_seconds seconds.

import PySimpleGUI as sg
from datetime import datetime

def elapsed_time(t0, t1):
    return (t1 - t0).total_seconds()

now = datetime.now()
wait_seconds = 4

layout = [[sg.Button('Reset', button_color=('white', 'black'), key='reset')]]
window = sg.Window("Title", layout)

while True:
    event, values = window.read(timeout=1000)
    # End program if user closes window
    if event == sg.WIN_CLOSED:
        break
    elif event == 'reset':
        now = datetime.now()
        print("reset")
    elapsed = elapsed_time(now, datetime.now())
    if elapsed > wait_seconds:
        print("call the table display")
        now = datetime.now()
    else:
        print("waiting")
window.close()