首页 > 解决方案 > 用进度条复制文件?

问题描述

我正在制作一个简单的程序,它使用 tkinter 和 shutil 来复制文件,没什么特别的。问题是没有迹象表明该过程何时完成,如果我正在复制大文件夹,程序会冻结,直到完成复制。我想要一个进度条,但不知道如何在 tkinter 中实现它。

from tkinter import *
from tkinter import filedialog
import shutil


def browseFiles():
    filename = filedialog.askdirectory(initialdir="/", title="Select a directory")
    label_file_explorer.configure(text="Directory Opened: " + filename, bg="grey")
    shutil.copytree(filename, r"J:\PCmover\ziptest\test")


window = Tk()
window.title('Beringia')
window.geometry("700x500")
window.config(background="white")
label_file_explorer = Label(window, width=100, height=4, bg="white", fg="blue")
button_explore = Button(window, text="Choose directory", command=browseFiles)
button_exit = Button(window, text="Quit", command=exit)
softwarename=Label(window, text="Welcome to Beringia!", width=100, height=4, fg="blue")
ver=Label(window, text="Ver 1.0", bg="grey", fg="blue")

label_file_explorer.place(x=0, y=200)
button_explore.place(x=305, y=80)
button_exit.place(x=335, y=120)
softwarename.place(x=0, y=0)
ver.place(x=659, y=479)
window.mainloop()

标签: pythontkintercopyprogress-barshutil

解决方案


推荐阅读