0

I have a python script with a bunch of 'for' loops (with different iterations). I want to implement a progress bar for each of these loops so that for each iteration in these loops the bar is updated. I know how to implement a progress bar, but writing a progress bar for each loop will take time, not to mention I will be adding more such loops later.

The idea in my head right now is this: I want to know whether it is possible to 'do some task' whenever the program starts iterating through a for loop? Basically:

[some previous task] --> (for loop) --> (print("for loop initiated!")/ do something) --> <start iteration through for loop> --> <reached end of for loop> --> (print("done!")/do something else) --> [next task on script]

In summary, I want to write a function/method in the script such that it notifies itself whenever a for loop is initiated and runs a progress bar on its own.

Is there any way to do this? Or do you maybe have better ideas? And a side note here, if there are any alternative progress bar suggestions, they should be compatible with tkinter because I am also using that in the script.

Phnx Drm
  • 1
  • 2
  • You might want to check the related questions to the right and might want to go through [Python Progress Bar](https://stackoverflow.com/questions/3160699/python-progress-bar), or search specifically with tkinter may get you [tkinter gui with progress bar](https://stackoverflow.com/questions/33768577/tkinter-gui-with-progress-bar), along with [How to update a progress bar in a loop?](https://stackoverflow.com/questions/36516497/how-to-update-a-progress-bar-in-a-loop). As it is the question has basically been asked before and rather broad. – metatoaster Apr 07 '21 at 04:46
  • Yes, I already have gone through them. But my issue is to avoid having to write a progress bar for every loop in the script, which is a lot of them each with different iterations. I was thinking that if I/interpreter could know where a loop iteration has started then I/it could implement a progress bar immediately and so avoid having to write them over and over. The method in question should be able to detect when an iteration has started and so implement a progress bar automatically. – Phnx Drm Apr 07 '21 at 05:09
  • You will need to understand that any library you pick may have their own limitations. The answers are essentially what must be done when you pick tkinter as your GUI library. You may want to search around for examples, such as [this one](https://stackoverflow.com/questions/7310511/how-to-create-downloading-progress-bar-in-ttk) for further ideas. – metatoaster Apr 07 '21 at 05:26

0 Answers0