简单小练习_图片压缩工具
# _*_ 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()
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步