威望0
积分7946
贡献0
在线时间763 小时
UID1
注册时间2021-4-14
最后登录2024-11-21
管理员
- UID
- 1
- 威望
- 0
- 积分
- 7946
- 贡献
- 0
- 注册时间
- 2021-4-14
- 最后登录
- 2024-11-21
- 在线时间
- 763 小时
|
[mw_shl_code=python,true]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()
[/mw_shl_code] |
|