Python图形界面开发入门01-compress image

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_38316655/article/details/84729674
from PIL import Image as Img
from tkinter import *
from tkinter.filedialog import *
import os

info = {
    'path' : [],
}

def make_app():
    app =Tk()
    Label(app, text='Image compress tool').pack()
    Listbox(app, name="lbox", bg='#f2f2f2').pack(fill=BOTH, expand=True)
    Button(app, text='open', command=ui_getdata).pack()
    Button(app, text='compress', command=compress).pack()
    app.geometry('300x400')
    return app

def ui_getdata():
    f_names = askopenfilenames()
    info['path'] = f_names
    lbox = app.children['lbox']
    if info['path']:
        for name in f_names:
            lbox.insert(END, name.split("/")[-1])

def compress():
    for f_path in info['path']:
        output = 'C:/Users/PC-CYQ/Desktop/output/'
        if not os.path.exists(output):
            os.mkdir(output)
        name = f_path.split('/')[-1]
        image = Img.open(f_path)
        image.save(output+"c_"+name, quality=60)

app = make_app()
app.mainloop()

 

展开阅读全文

没有更多推荐了,返回首页