1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| import datetime import pytesseract from PIL import Image import tkinter
root = tkinter.Tk() root.title("OCR图片转文字")
screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight()
x = (screen_width - 500) // 2 y = (screen_height - 300) // 2
root.geometry("500x300+{}+{}".format(x, y))
text = tkinter.Text(root, font=("微软雅黑", 10, 'bold')) text.place(x=0, y=0, width=350, height=300) text.config(fg="black") text.insert("end", "hello")
lab_one = tkinter.Label(root, text='URL:', font=("Arial", 16, 'bold')) lab_one.place(x=360, y=30)
entry_id = tkinter.Entry(root, font=('Arial', 12, 'bold')) entry_id.place(x=410, y=30) entry_id.insert("end","-1")
lab_now = tkinter.Label(root, text='0', font=('Arial', 20, 'bold')) lab_now.place(x=450, y=70)
def data(): y = '_' + str(datetime.datetime.now().year) m = '-' + str(datetime.datetime.now().month) + '-' d = str(datetime.datetime.now().day) + "_" return y + m + d
def button_click(): url=entry_id.get() if(url=='-1'): url=str(int(lab_now.cget("text"))+1) lab_now.config(text=url) elif(int(url)>int(lab_now.cget("text"))): lab_now.config(text=url) image_url='E:\\截图\\Orange'+data()+url+".png" print(image_url) try: image=Image.open(image_url) except: lab_now.config(text=str(int(url)-1)) out = pytesseract.image_to_string(image, lang="chi_sim+eng", config="--psm 6")
text.delete("1.0","end") text.insert("1.0",out)
button1=tkinter.Button(root,text="获取",font=("Arial",16,'bold'),command=button_click) button1.place(x=360,y=70)
def click_next(): entry_id.delete(0,"end") entry_id.insert(0,"-1") button_click()
button_go=tkinter.Button(root,text="max_next",font=("微软雅黑",10,'bold'),command=click_next) button_go.place(x=360,y=120)
if __name__ == '__main__': root.mainloop()
|