# _*_ coding=utf-8 _*_ from PIL import Image as Img from tkinter import * from tkinter.filedialog import * from tkinter import messagebox import os # ui # ui update # business info = { 'path':[] } def make_app(): app = Tk() Label(app, text='Image compress tool', font=('Hack',20,'bold')).pack() Listbox(app, name='lbox', bg='#f2f2f2').pack(fill=BOTH, expand=True) Button(app, text='open', command=ui_getdata).pack() Button(app, text='compresss', command=compress).pack() app.geometry('300x400') return app def ui_getdata(): f_names = askopenfilenames() lbox = app.children['lbox'] info['path'] = f_names if info['path']: for name in f_names: lbox.insert(END, name.split('/')[-1]) # abc.jpg def compress(): for f_path in info['path']: output = os.getcwd()+'/' name = f_path.split('/')[-1] image = Img.open(f_path) image.save(output+'c_'+name, quality=60) messagebox.showinfo(title='压缩完成',message='压缩完成') app = make_app() app.mainloop()