import os import tkinter as tk from PIL import Image """ 将python.py文件打包为exe文件 pip install pyinstaller pyinstaller -F photo_process_gui.py """ dpi = 96 # 1 inch=2.54cm width = 25.4 / 2.54 height = 19.05 / 2.54 width_pixel = width * dpi height_pixel = height * dpi window = tk.Tk() entry = tk.Entry(window, width=20) entry.pack() entry2 = tk.Entry(window, width=20) entry2.pack() # 修改图片尺寸 def resize_image(filein, fileout, w, h): img = Image.open(filein) # 调整大小 out=img.resize((w, h)) out.save(fileout) # 从GUI获取输入输出文件夹 def change_state(): in_path = entry.get() # 调用get()方法,将Entry中的内容获取出来 out_path = entry2.get() print(in_path, out_path) files = os.listdir(in_path) for file in files: resize_image(os.path.join(in_path, file), os.path.join(out_path, file), width_pixel, height_pixel) button = tk.Button(window, text='执行', command=change_state).pack() window.mainloop()