Python 如何通过pyqt5按钮启动多个函数实例?

Python 如何通过pyqt5按钮启动多个函数实例?,python,selenium-webdriver,pyqt,pyqt5,selenium-chromedriver,Python,Selenium Webdriver,Pyqt,Pyqt5,Selenium Chromedriver,嘿,我写了一个小小的自动购买机器人。 GUI是用PYQT5制作的 我有一个按钮,可以调用带有几个参数的函数。 我遇到的问题是 主窗口冻结 对于问题nr1,我无法多次单击按钮来多次触发该功能。(我想多次启动它) 我真的需要一些帮助 我的按钮: self.buttonSoleBox = QPushButton('Start Bot', self) self.buttonBox.move(20, 120) self.buttonBox.clicked.c

嘿,我写了一个小小的自动购买机器人。 GUI是用PYQT5制作的

我有一个按钮,可以调用带有几个参数的函数。 我遇到的问题是

  • 主窗口冻结
  • 对于问题nr1,我无法多次单击按钮来多次触发该功能。(我想多次启动它)
  • 我真的需要一些帮助

    我的按钮:

            self.buttonSoleBox = QPushButton('Start Bot', self)
            self.buttonBox.move(20, 120)
            self.buttonBox.clicked.connect(self.on_click)
    
    和我的按钮动作功能:

        def on_click(self):
    
            email = self.textbox.text()
            password = self.textbox1.text()
            aid = self.textbox2.text()
            payment = self.textbox4.text()
            paypalemail = self.textbox5.text()
            paypalpassword = self.textbox6.text()
            StartBotFunction(email, password, aid, payment, paypalemail, paypalpassword)
    
            self.textbox.setText("")
            self.textbox1.setText("")
            self.textbox2.setText("")
            self.textbox4.setText("")
            self.textbox5.setText("")
            self.textbox6.setText("")
    
    
    对于测试: 2文件:

    main.py

    from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QLineEdit, QLabel, QComboBox
    from PyQt5 import QtGui
    from selenium import webdriver
    import sys
    
    class App(QMainWindow):
    
        def __init__(self):
            super(App,self).__init__()
            self.title = 'whatever'
            self.left = 200
            self.top = 200
            self.width = 800
            self.height = 500
            self.setWindowIcon(QtGui.QIcon('icon.png'))
            self.setWindowTitle(self.title)
            self.setGeometry(self.left, self.top, self.width, self.height)
            self.initUI()
    
        def initUI(self):
    
            self.button1 = QPushButton('Start Bot', self)
            self.button1.move(20, 120)
            self.button1.clicked.connect(self.on_click)
    
            self.show()
    
    
        def on_click(self):
            word = "sneaker"
            StartBotFunction(word)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        ex = App()
        sys.exit(app.exec_())
    
    
    
    
    search.py

    from selenium import webdriver
    import time
    
    def StartBotFunction(word):
        word
        driver = webdriver.Chrome()
        driver.get('https://www.zalando.de/herren/?q=' + word )
    
        first = driver.find_element_by_xpath('//*[@id="z-nvg-cognac-root"]/div[1]/z-grid/z-grid-item[2]/div/div[5]/z-grid/z-grid-item[1]/div/a')
        first.click()
    
    
        while (driver.page_source).__contains__('Bewertung'):
            time.sleep(5)
            driver.refresh()
    
    
    当我为你们建立这个例子的时候,我发现当我这样做的时候,我遇到了我的主要问题 如果我删除while,我可以创建尽可能多的chromewindows,只要我点击按钮

    知道怎么解决吗

    while (driver.page_source).__contains__('Bewertung'):
    time.sleep(5)
    driver.refresh()```
    

    您必须在另一个线程中运行StartBotFunction:

    import sys
    import threading
    
    from PyQt5 import QtCore, QtWidgets
    
    import search
    
    
    class Widget(QtWidgets.QWidget):
        def __init__(self, parent=None):
            super(Widget, self).__init__(parent)
            self.lineedit = QtWidgets.QLineEdit("sneaker", placeholderText="word")
            button = QtWidgets.QPushButton("Press me")
            button.clicked.connect(self.on_click)
    
            flay = QtWidgets.QFormLayout(self)
            flay.addRow("Insert word:", self.lineedit)
            flay.addRow(button)
    
        @QtCore.pyqtSlot()
        def on_click(self):
            word = self.lineedit.text()
            threading.Thread(target=search.StartBotFunction, args=(word,)).start()
    
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        w = Widget()
        w.show()
        sys.exit(app.exec_())
    导入系统 导入线程 从PyQt5导入QtCore、QtWidgets 导入搜索 类小部件(qtwidts.QWidget): def uuu init uuu(self,parent=None): 超级(小部件,自我)。\uuuuu初始化\uuuuuuu(父级) self.lineedit=QtWidgets.QLineEdit(“运动鞋”,placeholder text=“word”) button=QtWidgets.QPushButton(“按我”) 按钮。单击。连接(单击时自行) flay=qtwidts.QFormLayout(self) flay.addRow(“插入单词:”,self.lineedit) flay.addRow(按钮) @QtCore.pyqtSlot() 单击时的def(自身): word=self.lineedit.text() threading.Thread(target=search.StartBotFunction,args=(word,).start() 如果名称=“\uuuuu main\uuuuuuuu”: app=qtwidts.QApplication(sys.argv) w=Widget() w、 show() sys.exit(app.exec_())提供一个