Python 3.x 对象没有属性,但已定义属性
我已经在自定义类中定义了一个属性,但是当我尝试访问它时,我一直收到AttributeErrorPython 3.x 对象没有属性,但已定义属性,python-3.x,pyqt5,Python 3.x,Pyqt5,我已经在自定义类中定义了一个属性,但是当我尝试访问它时,我一直收到AttributeError class SMainWindow(QMainWindow): def __init__(self): # Constructor super(SMainWindow, self).__init__() self.myapp = PyQtApp() self.layout = QVBoxLayout() self.
class SMainWindow(QMainWindow):
def __init__(self):
# Constructor
super(SMainWindow, self).__init__()
self.myapp = PyQtApp()
self.layout = QVBoxLayout()
self.label_text = ''
self.settings = scrudb.retrieve_settings('current')
self.competition = self.retrieve_competition()
self.set_competition(self.competition.id)
self.label = QLabel(self.label_text)
self.button_scrutineer = QPushButton('Scrutineer Competition')
self.button_comps = QPushButton('Change Competition')
self.button_comp = QPushButton('Edit Competition Details')
self.button_dancers = QPushButton('Add/Edit Competitors')
self.button_judges = QPushButton('Add/Edit Judges')
self.button_dancerGroups = QPushButton(
'Define Competitor Groups & Dances')
self.button_import = QPushButton('Import CSV')
self.button_delete = QPushButton('Delete Competition')
self.button_exit = QPushButton('Exit')
self.button_comps.clicked.connect(self.select_competition)
self.button_delete.clicked.connect(self.delete_competition)
self.button_exit.clicked.connect(self.exit_app)
if (self.competition == None):
self.disable_buttons()
self.layout.addWidget(self.label)
self.layout.addWidget(self.button_scrutineer)
self.layout.addWidget(self.button_comps)
self.layout.addWidget(self.button_comp)
self.layout.addWidget(self.button_dancers)
self.layout.addWidget(self.button_judges)
self.layout.addWidget(self.button_dancerGroups)
self.layout.addWidget(self.button_import)
self.layout.addWidget(self.button_delete)
self.layout.addWidget(self.button_exit)
self.myapp.setLayout(self.layout)
def set_competition(self, comp_id):
self.competition = scrudb.retrieve_competition(comp_id)
if (self.competition != None):
self.label_text = ('<center>Competition:<br><strong>%s</strong><br>%8s<br>%s</center>' % (self.competition.name, self.get_formatted_date(self.competition.eventDate), self.competition.location))
self.label.setText(self.label_text)
self.settings.lastComp = self.competition.id
scrudb.set_settings(self.settings)
return self.competition
else:
self.label_text = ('<center>No Competition Selected</center>')
return None
文件/Users/majikpig/mu_code/src/main/python/scrupinterface1.py,第182行,在set_竞赛中
self.label.setTextself.label\u文本
AttributeError:“SMainWindow”对象没有属性“label”您需要更改字段的顺序。。。在set competition函数中,您尝试访问尚未定义的字段
self.set_competition(self.competition.id)
self.label = QLabel(self.label_text)
在创建self.label之前,您正在呼叫set_competition。嗨,Matt!为了得到高质量的答案,请确保张贴高质量的问题。尽量更准确地描述主题,并从描述中去除所有杂音。也许你想把代码限制在重要的行内。谢谢你!