pyqt5小工具

  • Post author:
  • Post category:其他


**



更新时间:2020-12-30

**

python+qt编写的小工具。


开发工具:pycharm

电商工作常用到:

批量打开多个网址。查看页面

由网址前缀+后缀组成。自由组合。批量打开。

在这里插入图片描述

代码:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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.QtWidgets import QApplication, QMainWindow,QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
import webbrowser
import codecs
import time
import sys

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(492, 472)
        self.centralWidget = QtWidgets.QWidget(MainWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.splitter = QtWidgets.QSplitter(self.centralWidget)
        self.splitter.setGeometry(QtCore.QRect(10, 10, 461, 411))
        self.splitter.setOrientation(QtCore.Qt.Horizontal)
        self.splitter.setObjectName("splitter")
        self.widget = QtWidgets.QWidget(self.splitter)
        self.widget.setObjectName("widget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget)
        self.verticalLayout_2.setContentsMargins(11, 11, 11, 11)
        self.verticalLayout_2.setSpacing(6)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setSpacing(6)
        self.verticalLayout.setObjectName("verticalLayout")
        self.lineEdit = QtWidgets.QLineEdit(self.widget)
        self.lineEdit.setObjectName("lineEdit")
        self.verticalLayout.addWidget(self.lineEdit)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.verticalLayout.addWidget(self.lineEdit_2)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        self.textEdit = QtWidgets.QTextEdit(self.widget)
        self.textEdit.setObjectName("textEdit")
        self.verticalLayout_2.addWidget(self.textEdit)
        self.widget1 = QtWidgets.QWidget(self.splitter)
        self.widget1.setObjectName("widget1")
        self.formLayout_3 = QtWidgets.QFormLayout(self.widget1)
        self.formLayout_3.setContentsMargins(11, 11, 11, 11)
        self.formLayout_3.setSpacing(6)
        self.formLayout_3.setObjectName("formLayout_3")
        self.label = QtWidgets.QLabel(self.widget1)
        self.label.setObjectName("label")

        self.formLayout_3.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.label)
        self.spinBox = QtWidgets.QSpinBox(self.widget1)
        self.spinBox.setObjectName("spinBox")
        self.formLayout_3.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.spinBox)
        self.openButton = QtWidgets.QPushButton(self.widget1)
        self.openButton.setObjectName("openButton")
        self.formLayout_3.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.openButton)
        self.clearButton = QtWidgets.QPushButton(self.widget1)
        self.clearButton.setObjectName("clearButton")
        self.formLayout_3.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.clearButton)
        MainWindow.setCentralWidget(self.centralWidget)
        self.mainToolBar = QtWidgets.QToolBar(MainWindow)
        self.mainToolBar.setObjectName("mainToolBar")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        self.statusBar = QtWidgets.QStatusBar(MainWindow)
        self.statusBar.setObjectName("statusBar")
        MainWindow.setStatusBar(self.statusBar)

        self.openButton.clicked.connect(self.openNet)
        self.clearButton.clicked.connect(self.clearText)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "批量打开网站"))
        self.label.setText(_translate("MainWindow", "打开数量:"))
        self.label2.setText(_translate("MainWindow", "打开数量:"))
        self.openButton.setText(_translate("MainWindow", "打开"))
        self.clearButton.setText(_translate("MainWindow", "清空"))

    def clearText(self):
        self.textEdit.clear()

    def openNet(self):
        first = self.lineEdit.text()
        end = self.lineEdit_2.text()
        str = self.textEdit.toPlainText();
        strList = str.split("\n");

        for sku in strList:
            if len(sku) > 5:
                url = first + sku.strip() + end
                time.sleep(1)  # 打开间隔时间
                webbrowser.open(url)  # 打开网页

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())



版权声明:本文为weixin_44353958原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。