我在一个文件中有两个类。
主类将具有更新该类中的 UI 元素的方法。它创建另一个类的实例。
我想从另一个实例化的类更新主类中的 UI。
class Add(QtGui.QMainWindow,Ui_AddShotDetails):
def __init__(self):
super(Add,self).__init__()
self.setupUi(self)
def addDetails(self):
#Do some stuff and call method in Manager class
Manager.EpiChange() # I get the error at this line
class Manager(QtGui.QMainWindow,Ui_ShotManager):
def __init__(self):
super(Manager,self).__init__()
self.setupUi(self)
self.AddWindow = Add()
def EpiChange(self):
Manager.EpiCode = str(self.cmb_Epi.currentText())
# Update ui elements
def addShot(self):
self.AddWindow.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
win = Manager()
win.show()
sys.exit(app.exec_())
我得到以下回溯
Traceback (most recent call last):
File "D:\Manager.py", line 18, in addDetails
Manager.EpiChange()
TypeError: unbound method EpiChange() must be called with Manager instance as first argument (got nothing instead)
我尝试将此方法作为类方法使用@classmethod
,如果我使用它,我会得到以下回溯
Traceback (most recent call last):
File "D:\Manager.py", line 27, in EpiChange
Manager.EpiCode = str(self.cmb_Epi.currentText())
AttributeError: type object 'Manager' has no attribute 'cmb_Epi'