【发布时间】:2021-10-21 08:29:57
【问题描述】:
根据下面的代码,当我尝试从作为父 Main() 类的一部分的 addLineDialoge 函数中获取 MainTabIndex 值,并尝试在子 Dialoge_list 类中使用它时,出现 'AttributeError:' Main '对象没有属性'MainTabIndex' 发生错误。 请告诉我如何解决这个问题。
父类:
class Main(QMainWindow, Ui_MainWindow):
def __init__(self):
super(Main, self).__init__()
self.setupUi(self)
self.addLineButt.clicked.connect(self.addLineDialoge)
def addLineDialoge(self):
self.**MainTabIndex** = self.MainTab.currentIndex()
self.**ListTabIndex** = self.ListTab.currentIndex()
print(self.ListTabIndex)
addList = Dialoge_list()
addWaste = Dialoge_Waste()
if self.MainTab.currentIndex() == 0:
addList.exec()
elif self.MainTab.currentIndex() == 1:
addWaste.exec()
儿童班:
class Dialoge_list(QDialog, Ui_dialog_List):
def __init__(self):
super(Dialoge_list, self).__init__()
self.setupUi(self)
self.addItemButt.clicked.connect(self.addListToBase)
def addListToBase(self):
numCell = self.numLine.text()
thikCell = self.thikLine.text()
matCell = self.matLine.text()
sizeCell = self.sizeLine.text()
quantityCell = self.quantityLine.text()
dateinCell = self.dateinLine.text()
applyCell = self.applyLine.text()
noticeCell = self.noticeLine.text()
list_tab = [(numCell,
thikCell,
matCell,
sizeCell,
quantityCell,
dateinCell,
applyCell,
noticeCell)]
if "".__eq__(numCell) and "".__eq__(thikCell) and "".__eq__(matCell) and "".__eq__(
sizeCell) and "".__eq__(quantityCell) and "".__eq__(dateinCell) and "".__eq__(
applyCell) and "".__eq__(noticeCell):
emptyError = EmptyErrorDialoge()
emptyError.exec()
elif Main().**MainTabIndex** == 0 and Main().**ListTabIndex** == 0:
. . . .
【问题讨论】:
-
所需的功能用** ... **标记
标签: python class user-interface attributes parent