Web Analytics Made Easy - Statcounter
Skip to content

Custom Progress Meter / Progress Bar

Perhaps you don't want all the statistics that the EasyProgressMeter provides and want to create your own progress bar. Use this recipe to do just that.

script_launcher

import PySimpleGUI as sg

sg.theme('Dark Red')

BAR_MAX = 1000

# layout the Window
layout = [[sg.Text('A custom progress meter')],
          [sg.ProgressBar(BAR_MAX, orientation='h', size=(20,20), key='-PROG-')],
          [sg.Cancel()]]

# create the Window
window = sg.Window('Custom Progress Meter', layout)
# loop that would normally do something useful
for i in range(1000):
    # check to see if the cancel button was clicked and exit loop if clicked
    event, values = window.read(timeout=10)
    if event == 'Cancel' or event == sg.WIN_CLOSED:
        break
        # update bar with loop value +1 so that bar eventually reaches the maximum
    window['-PROG-'].update(i+1)
# done with loop... need to destroy the window as it's still open
window.close()