问题遇到的现象和发生背景
请看如下代码
问题相关代码,请勿粘贴截图
运行结果及报错内容
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2022/3/23 19:18
# @Author : 志在逍遥
# @File : xinjietu.py
# @Software: PyCharm
from PySide2.QtWidgets import QApplication
from PySide2.QtUiTools import QUiLoader
import sys
from PIL import ImageGrab
# 调用百度的接口识别图片内容
from aip import AipOcr
"""你的APPID AK SK"""
APP_ID = "**"
API_KEY = "**"
SECRET_KEY = "**"
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
class Stats:
def __init__(self):
# 从文件中加载UI定义
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
self.ui = QUiLoader().load('Screenshot_main_interface.ui')
# self.ui.MainWindow=self.ui.MainWindow()
self.ui.centralwidget.setWindowOpacity(0.1)
self.ui.pushButton_3.setStyleSheet(u"color: yellow;\n"
"background-color: pink;")
self.ui.pushButton_2.setStyleSheet(u"color: yellow;\n"
"background-color: pink;")
self.ui.pushButton_2.clicked.connect(self.handleCalc1)
self.ui.pushButton_3.clicked.connect(self.handleCalc2)
# self.ui.pushButton_4.clicked.connect(self.copyText)
# self.ui.pushButton_2.setStyleSheet("background-color: red;")
# self.ui.pushButton_3.setStyleSheet("background-color: yellow;")
# self.ui.textEdit.setText('这是截图文本框内容')
# self.ui.textEdit.setStyleSheet("background-color: pink;")
def handleCalc1(self):
# 图片保存
image = ImageGrab.grabclipboard() # 获取剪切板的图片
image.save('13.jpg') # 图片保存
# 打开13.jpg图片
with open('13.jpg', 'rb') as f:
image = f.read() # image就是这张图片的二进制内容
text = client.basicAccurate(image) # 调用百度的接口识别图片的内容
# print(text)
result = text['words_result']
for i in result:
self.ui.textEdit.append(i['words'])
def handleCalc2(self):
self.ui.textEdit.clear()
if __name__ == '__main__':
app = QApplication(sys.argv)
stats = Stats()
stats.ui.show()
sys.exit(app.exec_())