How to change the max value of a progressbar in pythonsimplegui?

Question:

I want to create a progressbar which has the length of the list as its max value.
I initialize it with max value 1000, but I want to change it after reading a csv file and getting the length of it. But it doesn’t work as I expect.
How can I achieve it?
Below is my current code.

from read_csv import get_csv_list
file_input_col = [sg.Text('CSV file'),
                  sg.InputText(key='INPUT_FILE', enable_events=True, size=(45,1)),
                  sg.FileBrowse('browse', file_types=((('CSV file', '*.csv'),)))]

ok_button = [sg.OK()]
cancel_button = [sg.Cancel()]
progress_bar = [sg.ProgressBar(1000, orientation='h', size=(20, 20), key='progressbar')]

# window layout
layout = [  file_input_col,
            ok_button,
            cancel_button,
            progress_bar]

# Create window object
window = sg.Window('test', layout)
progress_bar = window['progressbar']


# loop
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    if event =='OK':
        keyword_list = get_csv_list(values['INPUT_FILE'])
        progress_bar.update(max=len(keyword_list))
        for i in range(1000): # I will change this for loop later
            progress_bar.UpdateBar(i+1)
            event, values = window.read(timeout=10)
            if event == 'Cancel'  or event == sg.WIN_CLOSED:
                progress_bar.UpdateBar(0)
                break
window.close()```
Asked By: Light

||

Answers:

The pythonsimplegui ProgressBar Class uses a TKinter ProgressBar object called TKProgressBar to display the GUI. If the update method for the pythonsimplegui ProgressBar is not working as expected, you can try updating their TKinter ProgressBar directly instead:

progress_bar.TKProgressBar.TKProgressBarForReal.config(maximum=1000, length=len(keyword_list))
progress_bar.max_value = len(keyword_list)
Answered By: Jack Bosco
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.