From 1e9a052f27ed71f66eca2a4bf1589e0096b08fbc Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sat, 11 Aug 2018 19:36:07 -0400 Subject: [PATCH] Commented and fixed progress bar --- Demo_Machine_Learning.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Demo_Machine_Learning.py b/Demo_Machine_Learning.py index 6de6283f..3d2eeb0b 100644 --- a/Demo_Machine_Learning.py +++ b/Demo_Machine_Learning.py @@ -30,20 +30,27 @@ def MachineLearningGUI(): def CustomMeter(): - + # create the progress bar element progress_bar = sg.ProgressBar(10000, orientation='h', size=(20,20)) - + # layout the form layout = [[sg.Text('A custom progress meter')], [progress_bar], [sg.Cancel()]] + # create the form form = sg.FlexForm('Custom Progress Meter') + # display the form as a non-blocking form form.LayoutAndRead(layout, non_blocking=True) - + # loop that would normally do something useful for i in range(10000): + # check to see if the cancel button was clicked and exit loop if clicked button, values = form.ReadNonBlocking() - progress_bar.UpdateBar(i) - + if button == 'Cancel' or values == None: + break + # update bar with loop value +1 so that bar eventually reaches the maximum + progress_bar.UpdateBar(i+1) + # done with loop... need to destroy the window as it's still open + form.CloseNonBlockingForm() if __name__ == '__main__': CustomMeter()