diff --git a/by_PyQt5/window.py b/by_PyQt5/window.py new file mode 100644 index 0000000..316b065 --- /dev/null +++ b/by_PyQt5/window.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +""" +电脑二维码识别软件,对当前屏幕截屏,识别截屏里面的二维码,并将识别到的信息列出来 +可以双击具体链接打开,也可用点击打开全部一次性打开全部 +""" +import sys +from PIL import ImageGrab +from pyzbar import pyzbar +import webbrowser + +# Form implementation generated from reading ui file 'window.ui' +# +# Created by: PyQt5 UI code generator 5.15.9 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.setFixedSize(396, 233) # 固定窗口大小 + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.listWidget = QtWidgets.QListWidget(self.centralwidget) + self.listWidget.setGeometry(QtCore.QRect(30, 90, 321, 91)) + self.listWidget.setObjectName("listWidget") + self.pushButton = QtWidgets.QPushButton(self.centralwidget) + self.pushButton.setGeometry(QtCore.QRect(50, 20, 121, 51)) + self.pushButton.setObjectName("pushButton") + self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) + self.pushButton_2.setGeometry(QtCore.QRect(200, 30, 111, 41)) + self.pushButton_2.setObjectName("pushButton_2") + MainWindow.setCentralWidget(self.centralwidget) + self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + # 将相应事件与相应回调函数绑定 + self.pushButton.clicked.connect(self.grab) + self.pushButton_2.clicked.connect(self.open_url) + self.listWidget.itemDoubleClicked.connect(self.double_open) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "二维码截屏识别")) + self.pushButton.setText(_translate("MainWindow", "截屏识别")) + self.pushButton_2.setText(_translate("MainWindow", "打开全部")) + + # 以下为自定义函数,用来实现自定义功能,将与各个组件的相应事件绑定 + def grab(self): + img = ImageGrab.grab() + results = pyzbar.decode(image=img, symbols=[pyzbar.ZBarSymbol.QRCODE]) + self.listWidget.clear() + for i, result in enumerate(results): + url = result.data.decode('utf-8') + # print(url) + self.listWidget.insertItem(i, url) + + def open_url(self): + for i in range(self.listWidget.count()): + webbrowser.open(url=self.listWidget.item(i).text()) + + def double_open(self): + url = self.listWidget.selectedItems()[0].text() + webbrowser.open(url=url) + + +if __name__ == '__main__': + # 必须的app和sys.exit(和tk.mainloop一样) + app = QtWidgets.QApplication(sys.argv) + + # 将创建的ui实例化,应用起来 + ui = Ui_MainWindow() + MainWindow = QtWidgets.QMainWindow() + # ui只是框架,需要传入一个QMainWindow对象作为实体来应用该ui + ui.setupUi(MainWindow) + # 显示ui(窗口) + MainWindow.show() + + sys.exit(app.exec_()) diff --git a/by_PyQt5/window.ui b/by_PyQt5/window.ui new file mode 100644 index 0000000..7e298e3 --- /dev/null +++ b/by_PyQt5/window.ui @@ -0,0 +1,58 @@ + + + MainWindow + + + + 0 + 0 + 396 + 233 + + + + 二维码截屏识别 + + + + + + 30 + 90 + 321 + 91 + + + + + + + 50 + 20 + 121 + 51 + + + + 截屏识别 + + + + + + 200 + 30 + 111 + 41 + + + + 打开全部 + + + + + + + + diff --git a/by_PyQt5/window_pyuic_convert.py b/by_PyQt5/window_pyuic_convert.py new file mode 100644 index 0000000..c708258 --- /dev/null +++ b/by_PyQt5/window_pyuic_convert.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'window.ui' +# +# Created by: PyQt5 UI code generator 5.15.9 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(396, 233) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.listWidget = QtWidgets.QListWidget(self.centralwidget) + self.listWidget.setGeometry(QtCore.QRect(30, 90, 321, 91)) + self.listWidget.setObjectName("listWidget") + self.pushButton = QtWidgets.QPushButton(self.centralwidget) + self.pushButton.setGeometry(QtCore.QRect(50, 20, 121, 51)) + self.pushButton.setObjectName("pushButton") + self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) + self.pushButton_2.setGeometry(QtCore.QRect(200, 30, 111, 41)) + self.pushButton_2.setObjectName("pushButton_2") + MainWindow.setCentralWidget(self.centralwidget) + self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "二维码截屏识别")) + self.pushButton.setText(_translate("MainWindow", "截屏识别")) + self.pushButton_2.setText(_translate("MainWindow", "打开全部"))