Update the color of a progress bar in Python using a scale?
Okay, I started playing around with the method and I think the issue was that there was a lot of redundancy inside it (I'm still learning) which caused some conflict. I took a gamble and started removing small sections of code at a time to see how the method behaved and found the main problem was in my scale configurations. After removing unneeded code the method looks as follows:
def volumelevel(): if scalevar.get() <= 25: s.configure("Horizontal.TProgressbar", background='green') progress.configure(style="Horizontal.TProgressbar", value=scalevar.get()) elif scalevar.get() <= 75: s.configure("Horizontal.TProgressbar", background='yellow') progress.configure(style="Horizontal.TProgressbar", value=scalevar.get()) elif scalevar.get() <= 90: s.configure("Horizontal.TProgressbar", background='orange') progress.configure(style="Horizontal.TProgressbar", value=scalevar.get()) elif scalevar.get() <= 100: s.configure("Horizontal.TProgressbar", background='red') progress.configure(style="Horizontal.TProgressbar", value=scalevar.get())
I had the Style()
declaration, and the theme in the root portion of my code (from a previous example I found) so I took that out.
I took the color name out of the name of my styles as this had no effect on the method.
I took the scale configurations out completely as the attributes were being called in the scale object itself and therefore I used the command inside my scale object to call the method I created instead of set the value of the progress bar.
And now the progress bar changes color in real time based on the value of the scale.