php中文网 | cnphp.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 489|回复: 0

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

[复制链接]

2623

主题

2630

帖子

9319

积分

管理员

Rank: 9Rank: 9Rank: 9

UID
1
威望
0
积分
6574
贡献
0
注册时间
2021-4-14
最后登录
2024-4-26
在线时间
667 小时
QQ
发表于 2022-6-7 09:03:26 | 显示全部楼层 |阅读模式
[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]





上一篇:批量NDVI时序
下一篇:基于tkinter的Python文本转语音
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|php中文网 | cnphp.com ( 赣ICP备2021002321号-2 )51LA统计

GMT+8, 2024-4-26 08:53 , Processed in 0.183353 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

申明:本站所有资源皆搜集自网络,相关版权归版权持有人所有,如有侵权,请电邮(fiorkn@foxmail.com)告之,本站会尽快删除。

快速回复 返回顶部 返回列表