猿问

PyQT5 信号连接方法未实际绑定方法

我正在创建一个python应用程序。

链接到 ui.py 和 app.py: https://gist.github.com/tbhaxor/f68387d49bc59b2bdd025512c17a2534

app.py


from PyQt5 import QtWidgets, QtCore

from ui import Ui_MainWindow

from selenium.webdriver.chrome.webdriver import WebDriver

from selenium.webdriver.chrome.options import Options

import os

import traceback

import pickle as pkl

from pathlib import Path

from typing import List, Dict, Union



class Application(Ui_MainWindow):

    def __init__(self,

                 window: QtWidgets.QMainWindow,

                 driver: WebDriver = None):

        self.parent = window

        self.driver = driver

        self.setupUi(window)

        self.retranslateUi(window)


        qtRectangle = window.frameGeometry()

        centerPoint = QtWidgets.QDesktopWidget().availableGeometry().center()

        qtRectangle.moveCenter(centerPoint)

        window.move(qtRectangle.topLeft())

        self.__makeHandlers()


        self.file = os.path.join(Path.home(), "_linkedin.db")

        self.db: Dict[str, str] = {

            "api": "",

            "email": "",

            "password": "",

            "sent": [],

            "delay": 10,

            "template": ""

        }

        self.search_limit.valueChanged.connect(print)

        pass


    def __makeHandlers(self):

        self.search_limit.valueChanged.connect(print)

        pass


    def handle_fetch(self):

        pass


    def __login(self):

        driver.get("https://www.linkedin.com/login")

        # /html/body/div[1]/main/div/form/div[1]/input

        # /html/body/div[1]/main/div/form/div[2]/input

        # /html/body/div[1]/main/div/form/div[4]/button

        pass


    pass



if __name__ == "__main__":

    import sys


    try:

        opts = Options()

        opts.headless = os.environ.get("PYDBG", "0") != "1"

        driver: WebDriver = WebDriver(options=opts)

        app = QtWidgets.QApplication(sys.argv)



jeck猫
浏览 104回答 1
1回答

牛魔王的故事

问题很简单:通过执行 setupUi 方法,您正在创建内部小部件,如果第二次运行 setupUi 会发生什么情况?好吧,旧的小部件被删除并创建了新的小部件。在你的情况下,你首先在应用程序的构造函数中调用了 setupUi,并且在 之后再次调用它,在第一次调用时,你建立了连接,然后将其删除,因此连接已断开。解决方案:只需调用安装程序Ui一次。也没有必要调用重译Ui,因为安装Ui已经这样做了。ui = Application(MainWindow)class Application(Ui_MainWindow):    def __init__(self,                 window: QtWidgets.QMainWindow,                 driver: WebDriver = None):        self.parent = window        self.driver = driver        self.setupUi(window)        # self.retranslateUi(window) # remove this line        qtRectangle = window.frameGeometry()        # ...if __name__ == "__main__":    import sys    try:        opts = Options()        opts.headless = os.environ.get("PYDBG", "0") != "1"        driver: WebDriver = WebDriver(options=opts)        app = QtWidgets.QApplication(sys.argv)        MainWindow = QtWidgets.QMainWindow()        ui = Application(MainWindow)        # ui.setupUi(MainWindow) # remove this line        MainWindow.show()        app.exec_()    except Exception:        print(traceback.format_exc())    finally:        driver.quit()
随时随地看视频慕课网APP

相关分类

Python
我要回答