from aip import AipImageClassify,AipOcr import tkinter as tk from tkinter import filedialog window = tk.Tk() window.title("图片文字识别") # window.geometry('500*350+800+300') def click(): file_path = filedialog.askopenfilename() #文件路径 app_id = '16575748' api_key = 'cgRELw4wo2lajhaVjTXR7a9Q' secret_key = '8FTRcbn3iYp3fGyIMhAQrWmSyUGN9BdU' client = AipOcr(app_id, api_key, secret_key) def get_file_content(filepath): with open(filepath, "rb")as fp: return fp.read() image = get_file_content(file_path) client.basicGeneral(image) options = {} options['baike_num'] = 5 a = client.basicGeneral(image, options) e1.insert("end",a) b = tk.Button(window,text = "上传图片", command=click, width=10, font="微软雅黑 12") b.grid(row=1,column=1) e1 = tk.Text(window, height=20) e1.grid(row=3,column=1) window.mainloop() 最后在cmd下转换成可执行文件:pyinstaller -F -w image_discern.py