Python Forum

Full Version: Progress bar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
is there a way to show the progress bar using PySimpleGUI, while the script is running, no use with a for loop in the script, just showing the progress bar as long as the script is doing whatever ever asked, Thx!

See referred code I have in here :
import PySimpleGUI as sg
def gui():
    sg.theme("Dark Teal 7")
layout = [
    [sg.Text("""Hello """ + os.getlogin() + """, to run the loader click GO!""",
             size=(30, 3))],
    [sg.Submit('GO'), sg.Cancel()],

]

window = sg.Window("MyLoader", layout)
window_output = window.read()
window.close()

if window_output == ('GO', {}):

#here to start the progress bar untill what below asked finished
Please wrap posted code in Python tags so indentation is retained.

The pysimplegui documentation has a nice example for using the progress bar in a dialog.

https://pysimplegui.readthedocs.io/en/latest/
Look for : Progress Meter in Your window

I used that to write this:
import PySimpleGUI as sg

duration = 100
layout = [
    [sg.Text("Progress bar demo")],
    [sg.ProgressBar(duration, orientation='h', size=(20, 20), key='progressbar')],
    [sg.Button('Start'), sg.Button('Stop'), sg.Button('Resume')],
]

window = sg.Window("Demo", layout)
progress_bar = window["progressbar"]
running = False
while True:
    event, values = window.read(timeout=100)
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == "Start":
        progress = 0
        running = True
    elif event == "Stop":
        running = False
    elif event == "Resume":
        running = True
    if running:
        progress += 1
        if progress > duration:
            print("done")
            break
        progress_bar.UpdateBar(min(1000, progress))

window.close()
You would replace the progress counter with some actual measure of progress and the start, stop and resume events would get tied into the process you are doing.