Python Forum
[Tkinter] progressbar
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] progressbar
#1
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
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()
Reply
#3
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#4
Not sure what you mean, you can set the maximum value to anything you would like, it defaults to 100.
Reply
#5
(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 is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#6
https://tkdocs.com/shipman/ttk-Progressbar.html
Reply
#7
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#8
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.
Reply
#9
(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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#10
You cannot use sleep in a gui. That is a big no-no.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Progressbar with start and stop jelo34 3 4,981 Nov-30-2020, 03:36 AM
Last Post: deanhystad
  [Tkinter] Progressbar value update issue Roshan 7 3,346 Apr-22-2020, 04:02 PM
Last Post: deanhystad
  [Tkinter] Can't get progressbar to update frednet 0 1,670 Feb-24-2020, 10:53 PM
Last Post: frednet
  Adding Progressbar to button aniyanetworks 9 10,052 Feb-07-2019, 11:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020