I am a newbie. Ive written a small code, which should allow me to change from one ui to another. Unfortunately i get following Error Message:
"GUI_PYQT\main.py", line 33, in init self.ui.pushButton.clicked.connect(self.hello) AttributeError: 'MainWindow' object has no attribute 'hello'"
can someone help me? Here is my Code:
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_())
Your hello
function is part of the HomeScreen
class but you are trying to connect and therefore run it from inside MainWindow
. Since that class doesn't have a function with that name, it throws an error.