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

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()

 

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页