I am trying to learn the use of Class inheritance. I have read several tutorials but get stuck here, error when run is:
AttributeError: type object 'Ui_QMainWindow' has no attribute 'START'
This is just a sample code, I actually want to reference several buttons, slider and text from Ui_QMainWindow. The reason why I declare both Classes as Objects is because eventually I want to run the StopButton Class as a thread.
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QObject
class StopButton(QObject):
def __init__(self):
super(StopButton, self).__init__()
def Stop_Pressed(self):
Ui_QMainWindow.START.setEnabled(False)
class Ui_QMainWindow(QObject):
def __init__(self):
super(Ui_QMainWindow, self).__init__()
def setupUi(self, QMainWindow):
QMainWindow.setObjectName("QMainWindow")
QMainWindow.resize(400, 400)
# Main Window
self.centralwidget = QtWidgets.QWidget(QMainWindow)
self.centralwidget.setObjectName("centralwidget")
# STOP Button
self.STOP = QtWidgets.QPushButton(self.centralwidget)
self.STOP.setGeometry(QtCore.QRect(10, 10, 60, 60))
self.STOP.setStyleSheet("QPushButton"
"{"
"background-color : red;"
"}"
"QPushButton::pressed"
"{"
"background-color : red;"
"}"
)
self.STOP.setObjectName("STOP")
self.STOP.setDisabled(False)
self.STOP.clicked.connect(StopButton.Stop_Pressed)
# self.STOP.clicked.connect(StopButton.Stop_Pressed(self))
# START button
self.START = QtWidgets.QPushButton(self.centralwidget)
self.START.setGeometry(QtCore.QRect(10, 80, 60, 60))
self.START.setStyleSheet("QPushButton"
"{"
"background-color : lime;"
"}"
"QPushButton::pressed"
"{"
"background-color : lime;"
"}"
)
self.START.setDisabled(False)
QMainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(QMainWindow)
def retranslateUi(self, QMainWindow):
#
_translate = QtCore.QCoreApplication.translate
QMainWindow.setWindowTitle(_translate("QMainWindow", "Test"))
self.STOP.setText(_translate("QMainWindow", "STOP"))
self.START.setText(_translate("QMainWindow", "START"))
def main():
app = QtWidgets.QApplication(sys.argv)
QMainWindow = QtWidgets.QMainWindow()
ui = Ui_QMainWindow()
ui.setupUi(QMainWindow)
QMainWindow.show()
sys.exit(app.exec_())
main()