Python Forum

Full Version: progressbar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a name confusion.
In another language I used progressbars like this:
eg. maxValue = 100, step = 1 etc, but the steps are added by a loop, so the sum of the "steps" = fill of the progressbar.

In ttk i found a progressbar, but that seems to be time bound, filling the progressbar as a funtion of time. (with start and stop).

That's not what I need, I want a "manual controlled" one Smile
What do you call that in Python/tkinter/ttk ?

The alternative of course is using a "long" label, and fill that with '******' (or whatever) as action progresses.
(That would give me extra freedom in controlling the bg color, when things get close to the finish) Smile
But maybe the "progressbar" i'm looking for has similar methods.
thx,
Paul
The ttk.Progressbar can be manually controlled, see the following example:
import tkinter as tk
from tkinter import ttk


class MainFrame(tk.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, *kwargs)
        label = tk.Label(self, text="select value")
        label.pack(padx=5, pady=5)
        self.combobox = ttk.Combobox(self, values=list(range(101)))
        self.combobox.pack(padx=5, pady=5)
        self.combobox.bind("<<ComboboxSelected>>", self.on_combobox)
        self.progressbar = ttk.Progressbar(self, mode="determinate")
        self.progressbar.pack(padx=5, pady=5)

    def on_combobox(self, event):
        combo_value = self.combobox.get()
        self.progressbar.configure(value=combo_value)


if __name__ == "__main__":
    app = tk.Tk()
    main_frame = MainFrame(app)
    main_frame.pack()
    app.mainloop()
Thanks, I can see that it works.
Is my conclusion right that I have to work in percentages and
not in absolute numbers ?

thx,
Paul
Not sure what you mean, you can set the maximum value to anything you would like, it defaults to 100.
(Aug-30-2021, 08:50 AM)Yoriz Wrote: [ -> ]Not sure what you mean, you can set the maximum value to anything you would like, it defaults to 100.

OK, did not realize that 100 was the default.
Seems to do what i want.

Thanks
Paul
It appears i was looking in the wrong place for info on progressbar.
I have it working now, but still have a question.

For updates (bar moves forward) there seem to be 2 possibilities:
a) progbar.config(value= 12345)
or
b) use a kind of stringvar() (root, ...,...,variable = myVar, ...)

I collect the update values first in a list + validate them.
The simplest update would be alternative (a):
v = [100,200,300]
for x in v:
    progBar.config(value=x)
But this goes too fast, i want it to move "slowly". like a real progressbar.
I can throw in a time.sleep(...), and also a root.update(). This does the job.

But is this the best way? Should i investigate alternative (b) in some way?

thx,
Paul
I would use "after" to execute a function every 1/10 of a second or so. The function gets the current value of whatever you want to show progress for, and sets the progress bar to this value.
(Sep-01-2021, 03:30 AM)deanhystad Wrote: [ -> ]I would use "after" to execute a function every 1/10 of a second or so. The function gets the current value of whatever you want to show progress for, and sets the progress bar to this value.

Yep, works! Looks better than just sleep().

thx,
Paul
You cannot use sleep in a gui. That is a big no-no.