python 3.x - tkinter progress bar with file list -


i have loop read files in python below:

def rfile():     filename in filelist: …. 

how can add tkinter progress bar linked loop , size of filelist (start before loop , close after loop)?.

thx

this little script should demonstrate how that:

import tkinter tk time import sleep  # truncation make progressbar more accurate # note no progressbar perfect math import trunc  # need ttk module tkinter import ttk  # demonstrate filelist = range(10)  # how increase each iteration # formula in proportion length of progressbar step = trunc(100/len(filelist))  def main():     """put loop in here"""     filename in filelist:         # sleeping represents time consuming process         # such reading file.         sleep(1)          # demonstrate         print(filename)          # update progressbar         progress.step(step)         progress.update()      root.destroy()  root = tk.tk()  progress = ttk.progressbar(root, length=100) progress.pack()  # launch loop once window loaded progress.after(1, main)  root.mainloop() 

you can tweak satisfy needs.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -