#压缩软件 #设计界面 Import tkinter import tkinter.filedialog import zipfile import os import tkinter.messagebox root = tkinter.t K () Root.title (' Compressed Software 1.0 ') root.minsize (300,400) #设置需要压缩路径变量 zipfilename = [] #添加文件的函数 def addfile (): #全局化变量 glob Al zipfilename #弹出文件选框 files = tkinter.filedialog.askopenfilenames (title = ' Please select the file that needs the sub-cable ') #将选择的文件加入列表中 Zipf Ilename + = list (files) #将信息组成字符串书写 filesstr = ' \ n '. Join (zipfilename) #将文件的信息写入lable显示 lable[' text ' = File SSTR #压缩文件函数 def zip_file (): Path = '/home/caohaifeng/pycharmprojects/text.zip ' #打开或者创建压缩文件 ZP = ZipFile. ZipFile (Path, ' W ') #添加文件 for filename in zipfilename:zp.write (filename,os.path.basename (filename)) #关闭 Compressed file Zp.close () #判断压缩文件是否创建成功 if os.path.exists (path): tkinter.messagebox.showinfo (title = ' Information ', MESSAG E = ' file compression succeeded: ' + path ' else:tkinter.messagebox.showerror (title = ' ERROR ', message = ' compressed file failed.
') #解压文件函数 def unzip_file (): #选择需要解压的文件Zipfilepath = Tkinter.filedialog.asksaveasfilename () #选择解压的路径 Unzipfilepath = Tkinter.filedialog.askdirectory () #解压操作 ZP = ZipFile. ZipFile (Zipfilepath) #解压所有 Zp.extractall (Unzipfilepath) #关闭文件 zp.close () #摆放按钮 btn_add = Tkinter. Button (root,text = ' Add file ', command = addfile) btn_add.place (x = 20,y =) Btn_zip = Tkinter. Button (root,text = ' compressed file ', command = zip_file) btn_zip.place (x = 110,y =) Btn_unzip = Tkinter. Button (root,text = ' extract file ', command = unzip_file) btn_unzip.place (x = 200,y =) #显示信息区域 lable = Tkinter. Label (root,text = ' no file info ', bg = ' #abcdef ', anchor = ' NW ', justify = ' left ') lable.place (x =, y = 70,width =, height = 310) Root.mainloop ()