3

I have created a Python Script to download data using an API. And I have put a simple GUI on top of it as well using PySimpleGUI.

However, while the data is being downloaded, I want to show a indeterminate progressbar or something like that, which will exit on its own after the download completes.

Is there any way to implement this requirement?

Yash Sharma
  • 324
  • 6
  • 25

1 Answers1

5

Two ways easily for it, element sg.ProgressBar or simple sg.Text with different length of string, maybe , to show the state of progress.

Demo_Progress_Meters

or

enter image description here

from random import randint
import PySimpleGUI as sg

sg.theme('DarkBlue')

layout = [[sg.Text('', size=(50, 1), relief='sunken', font=('Courier', 11),
    text_color='yellow', background_color='black',key='TEXT')]]
window = sg.Window('Title', layout, finalize=True)
text = window['TEXT']
state = 0
while True:

    event, values = window.read(timeout=100)

    if event == sg.WINDOW_CLOSED:
        break
    state = (state+1)%51
    text.update('█'*state)

window.close()

Note: remember to use monospaced font, otherwise the length of sg.Text will be different as length of state string.

Depend on progress of job to set state of progress.

Jason Yang
  • 11,284
  • 2
  • 9
  • 23