Issue
i'm not very deep into Python for now. But i have in my opinion very simple, but non googable question.
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(659, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
...Code Omitted...
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(190, 370, 391, 31))
self.label.setObjectName("label")
self.label.setFont(QtGui.QFont("Arial",20))
self.label.setStyleSheet("color:white")
...Code Omitted...
MainWindow.setStatusBar(self.statusbar)
...Code Omitted...
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def AddTextToString(self, text123):
_translate = QtCore.QCoreApplication.translate
self.label.setText(_translate("MainWindow",text123))
class MyThread(QThread):
...Code Omitted...
def run(self):
...Code Omitted...
Ui_MainWindow().AddTextToString("Hello Word")
all i want to do, is to invoke a method, from another class with a passing variable from another method inside another class.
AttributeError: 'Ui_MainWindow' object has no attribute 'label'
Solution
First the variable self.label
is initialized once setupUI
method is called not in __init__
so you should call the setupUI
method after initialization of Ui_MainWindow
Second You can't call Ui_MainWindow().AddTextToString("Hello Word")
as AddTextToString
is not static method and it modifies class variable..
You need to create object of Ui_MainWindow
like self.ui_window = Ui_MainWindow()
and call self.ui_window.AddTextToString("Hello World")
Answered By - Ayush Shah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.