Update Tkinter progress bar
In event driven programming (GUIs) you can't have a blocking loop like your for loop. You have to set an event using after
to run a function again. This marries well with iterators:
from Tkinter import *import ttkimport numpy as nproot = Tk()files = iter(np.arange(1,10000))downloaded = IntVar()def loading(): try: downloaded.set(next(files)) # update the progress bar root.after(1, loading) # call this function again in 1 millisecond except StopIteration: # the files iterator is exhausted root.destroy()progress= ttk.Progressbar(root, orient = 'horizontal', maximum = 10000, variable=downloaded, mode = 'determinate')progress.pack(fill=BOTH)start = ttk.Button(root,text='start',command=loading)start.pack(fill=BOTH)root.mainloop()