For example, I want to change the text of a button by binding it to a function from another class. But I get an error on the line self.ui.pushButton.setText("OK")
:
AttributeError: 'bool' object has no attribute 'ui'
Here is main.py code:
from PySide6.QtWidgets import QApplication, QWidget
import test_gui
class App(QWidget):
def __init__(self):
QWidget.__init__(self)
self.ui = test_gui.Ui_Form()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(Second.func)
class Second(App):
def __init__(self):
App.__init__(self)
def func(self):
self.ui.pushButton.setText("OK")
if __name__ == "__main__":
app = QApplication([])
mw = App()
mw.show()
app.exec()
Here is test_gui.py code:
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'test_gui.ui'
##
## Created by: Qt User Interface Compiler version 6.2.4
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QPushButton, QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(392, 279)
self.pushButton = QPushButton(Form)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(120, 110, 75, 24))
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))
self.pushButton.setText(QCoreApplication.translate("Form", u"PushButton", None))
# retranslateUi
Please tell me what is the problem?