"""winzipfile打包文件夹小程序,本程序会递归地把文件夹中的每一个文件添加到一个压缩包中""" import os import zipfile from tkinter import * from tkinter import filedialog,messagebox window = Tk() path = filedialog.askdirectory(parent=window,initialdir="/",title='请选择一个文件夹。') print("你选择的文件夹是:",path) zipf = zipfile.ZipFile( 'c:/zipfile.zip', mode='w') for root,dirs,files in os.walk(path): for file in files: filename = root + os.sep + file print(filename) zipf.write(filename) zipf.close() messagebox.showinfo("完毕","OK") window.destroy() #os.system("explorer " + path)