admin 发表于 2022-6-7 09:03:26

基于tkinter、ttkbootstrap的Python图片识别文字

import pytesseract
import ttkbootstrap as ttk
from ttkbootstrap import Style
from PIL import Image

style = Style(theme = "cosmo")
root = style.master

def run():
    name = enter_content.get()
    img = Image.open(name)
    string = pytesseract.image_to_string(img)
    put = ttk.Text(root, width=48, height=55)
    put.insert(1.0,string)
    put.pack()


if __name__ == '__main__':
    root.title("图片识别文字")
    width = 700
    height = 450
    left = (root.winfo_screenwidth() - width) / 2
    top = (root.winfo_screenheight() - height) / 2
    root.geometry('%dx%d+%d+%d' % (width, height, left, top))
    label = ttk.Label(root, font=('黑体', 16), text='请输入文件名称:')
    label.pack()
    enter_content = ttk.StringVar()
    enter = ttk.Entry(root, width=58,textvariable=enter_content)
    enter.pack(pady=15)
    button = ttk.Button(root, text="识别",width=15, command=run)
    button.pack()
    root.mainloop()
页: [1]
查看完整版本: 基于tkinter、ttkbootstrap的Python图片识别文字