Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Progress bar
#1
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
Yoriz write Apr-11-2022, 02:48 PM:
Please post all code, output and errors (in thier entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Progress Indicator for Xmodem 0.4.6 KenHorse 1 1,984 Jan-30-2021, 07:12 PM
Last Post: bowlofred
  How can I add a progress bar for my software? aquerci 8 3,799 Nov-16-2019, 04:20 PM
Last Post: aquerci
  wget progress bar anasrocks 1 4,742 Jun-06-2019, 03:12 PM
Last Post: heiner55
  Progress Finished Question malonn 32 17,675 May-23-2018, 02:43 AM
Last Post: malonn
  how to progress with py jakegold98 1 2,641 Dec-05-2017, 02:58 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020