Python Tkinter Progressbar indeterminate on Toplevel while function running
Question: I need a progressbar which should show that the programm is still running
while a loop in a certain function is working, so all in all the issue is
simple.

I found some useful threads here but none helped me. I think I am missing a
detail.

Here is the function which needs up to 1 minute to be finished depending on
how many blogs are used:

    
    
    def bildinhalt_execute():
    
            tumblr_progress.start()
            taglist = tagliste_area.get("1.0", "end-1c")
            taglist = taglist.split(",")
            tumblr_alt_wert = tumblr_alt_wert_area.get("1.0", END)
            """ Resized das Bild proportional """
            with open('tumblr_credentials.json', 'r') as daten:
                data_for_login_tumblr_all = json.load(daten)
            for blog in data_for_login_tumblr_all:
                tumblr_zugangsdaten(data_for_login_tumblr_all[blog]["consumer_key"],data_for_login_tumblr_all[blog]["consumer_secret"],data_for_login_tumblr_all[blog]["oauth_token"],data_for_login_tumblr_all[blog]["oauth_token_secret"])
                im = Image.open(pfad_tumblr_1)
                basewidth = (im.size[0] - int(breitepx_area.get("1.0", END)))
                wpercent = (basewidth / float(im.size[0]))
                height = int((float(im.size[1]) * float(wpercent)))
                im = im.resize((basewidth, height), PIL.Image.ANTIALIAS)
                im.save(pfad_tumblr_1)
                """ Postet das Bild """
                pfad_tumblr_1_bild = pfad_tumblr_1
                pfad_tumblr_1_bild = str(pfad_tumblr_1_bild)
                tumblr_bild(blog, taglist, pfad_tumblr_1_bild, tumblr_alt_wert)
            tumblr_progress.stop()
    

I start the progress at the beginning and stop it at the end. The progressbar
itself is created on the toplevel root:

    
    
        tumblr_progress = ttk.Progressbar(tumblr_blog_root, orient='horizontal', mode='indeterminate')
        tumblr_progress.place(x = 300, y = 615)
    

The function is executed when this Button is clicked and thats the moment
where the prograssbar should start to show progress

    
    
        wordpress_button_bild = Button(tumblr_blog_root, text = "Bild", width=7, bg = "powder blue", command=bildinhalt_execute)
        wordpress_button_bild.place(x = 10, y = 10)
    

Am I on the right side? Or do I have probably to use multithreading for this,
have never worked with multiple threads could be very hard, so if
multithreading is needed, a hint would be nice where to start.

Thanks in advance!


Answer: Assuming you just want a moving progressbar, use the 'determinate' mode and
send the interval to the start() function. The label and counter below are
just there to do something for a while. If you want the progressbar to show
something like percent completion, then you would use "after" to schedule a
function call to update the progressbar with percent done, similar to the
label update's use of "after" in the code below.

    
    
    import Tkinter as tk
    from ttk import Progressbar
    
    class ProgressBar_Label(object):
        def __init__(self, parent):
            self.parent=parent
            self.ctr=0
    
            self.p = Progressbar(self.parent, orient=tk.HORIZONTAL, length=200,
                                 mode='determinate')
            self.p.grid()
            self.p.start(75)  ## 75 millisecond interval
    
            self.label=tk.Label(self.parent, text="Start", bg="lightblue", width=10)
            self.label.grid(row=1)
    
            tk.Button(self.parent, text="Quit", bg="orange",
                      command=self.parent.quit).grid(row=10)
    
            self.update_label()
    
        def update_label(self):
            self.ctr +=1
            self.label["text"]=str(self.ctr)
            if self.ctr < 100:
                self.parent.after(100, self.update_label)
            else:
                self.p.destroy()
                self.label["text"]="Finished"
    
    parent=tk.Tk()
    PL=ProgressBar_Label(parent)
    parent.mainloop()
    

