簡體   English   中英

PYQt5:Object 沒有屬性

[英]PYQt5: Object has no attribute

我是新手。 我寫了一個小代碼,它應該允許我從一個 ui 更改為另一個。 不幸的是,我收到以下錯誤消息:

“GUI_PYQT\main.py”,第 33 行, init self.ui.pushButton.clicked.connect(self.hello) AttributeError: 'MainWindow' object has no attribute 'hello'"

有人能幫我嗎? 這是我的代碼:


import sys

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QPushButton, QDockWidget, QToolButton
from PyQt5.QtCore import pyqtSlot

## ==> SPLASH SCREEN
from ui_splash_screen import Ui_SplashScreen

## ==> MAIN WINDOW
from ui_welcome_screen import Ui_MainWindow

## ==> HOME-SCREEN
from ui_home_screen import Ui_HomeScreen

## ==> GLOBALS
progressBarValue = 7

## WELCOME SCREEN
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setCursor(Qt.BlankCursor)
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.ui.pushButton.clicked.connect(self.hello)


## HOME-SCREEN
class HomeScreen(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_HomeScreen()
        self.ui.setupUi(self)
        self.setCursor(Qt.BlankCursor)
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

    def hello(self):
        self.main = Ui_HomeScreen
        self.show()


## SPLASH SCREEN
class SplashScreen(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_SplashScreen()
        self.ui.setupUi(self)
        self.setCursor(Qt.BlankCursor)

        ## UI ==> INTERFACE CODES
        ###############################################################

        ## REMOVE TITLE BAR
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)


        ## DROP SHADOW EFFECT
        self.shadow = QGraphicsDropShadowEffect(self)
        self.shadow.setBlurRadius(20)
        self.shadow.setXOffset(0)
        self.shadow.setYOffset(0)
        self.shadow.setColor(QColor(0, 0, 0, 0))
        self.ui.dropShadowFrame.setGraphicsEffect(self.shadow)

        ## QTIMER ==> START
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.appProgress)
        # TIMER IN MILLISECONDS
        self.timer.start(25)


        ## SHOW ==> MAIN WINDOW
        ###############################################################
        self.show()
        ## ==> END ##
        
            


    ## ==> APP FUNCTIONS
    ###################################################################

    def appProgress(self):
        global progressBarValue

        #Apply progressBarValue to the progressBar
        self.ui.progressBar.setValue(progressBarValue)
        progressBarValue = progressBarValue+1

        if progressBarValue > 100:
            # STOP TIMER
            self.timer.stop() 

            # SHOW MAIN WINDOW
            self.main = MainWindow()
            self.main.show()
            

            #CLOSE SPLASH SCREEN
            self.close()
        
        if progressBarValue >= 0:
            self.ui.label_3.setText("<strong>setting bootoptions.yo...")
        if progressBarValue >= 21:
            self.ui.label_3.setText("<strong>change screenlayout.uf...")
        if progressBarValue >= 53:
            self.ui.label_3.setText("<strong>load colors.ou")
        if progressBarValue >= 67:
            self.ui.label_3.setText("<strong>translate folder image_alternates.nd")
        if progressBarValue >= 92:
            self.ui.label_3.setText("<strong>preparing metadata.it")
        

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = SplashScreen()
    sys.exit(app.exec_())

hello function 是HomeScreen class 的一部分,但您正在嘗試連接並因此從MainWindow內部運行它。 由於該 class 沒有具有該名稱的 function,因此會引發錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM