'Unable to access variable that has been declared inside a class, outside of it
class makequestions(QMainWindow):
def __init__(self):
super(makequestions, self).__init__()
uic.loadUi("Addquestions.ui", self)
self.button= self.findChild(QPushButton,"pushButton")
self.table= self.findChild(QTableWidget,"tableWidget")
self.button.clicked.connect(self.data_collection)
self.show()
def data_collection(self):
zeze=self.table.item(0,0).text()
zeon=self.table.item(0,1).text()
zetw=self.table.item(0,2).text()
zeth=self.table.item(0,3).text()
zefo=self.table.item(0,4).text()
zefi=self.table.item(0,5).text()
onze=self.table.item(1,0).text()
onon=self.table.item(1,1).text()
ontw=self.table.item(1,2).text()
onth=self.table.item(1,3).text()
onfo=self.table.item(1,4).text()
onfi=self.table.item(1,5).text()
twze=self.table.item(2,0).text()
twon=self.table.item(2,1).text()
twtw=self.table.item(2,2).text()
twth=self.table.item(2,3).text()
twfo=self.table.item(2,4).text()
twfi=self.table.item(2,5).text()
thze=self.table.item(3,0).text()
thon=self.table.item(3,1).text()
thtw=self.table.item(3,2).text()
thth=self.table.item(3,3).text()
thfo=self.table.item(3,4).text()
thfi=self.table.item(3,5).text()
foze=self.table.item(4,0).text()
foon=self.table.item(4,1).text()
fotw=self.table.item(4,2).text()
foth=self.table.item(4,3).text()
fofo=self.table.item(4,4).text()
fofi=self.table.item(4,5).text()
fize=self.table.item(5,0).text()
fion=self.table.item(5,1).text()
fitw=self.table.item(5,2).text()
fith=self.table.item(5,3).text()
fifo=self.table.item(5,4).text()
fifi=self.table.item(5,5).text()
size=self.table.item(6,0).text()
sion=self.table.item(6,1).text()
sitw=self.table.item(6,2).text()
sith=self.table.item(6,3).text()
sifo=self.table.item(6,4).text()
sifi=self.table.item(6,5).text()
seze=self.table.item(7,0).text()
seon=self.table.item(7,1).text()
setw=self.table.item(7,2).text()
seth=self.table.item(7,3).text()
sefo=self.table.item(7,4).text()
sefi=self.table.item(7,5).text()
eize=self.table.item(8,0).text()
eion=self.table.item(8,1).text()
eitw=self.table.item(8,2).text()
eith=self.table.item(8,3).text()
eifo=self.table.item(8,4).text()
eifi=self.table.item(8,5).text()
nize=self.table.item(9,0).text()
nion=self.table.item(9,1).text()
nitw=self.table.item(9,2).text()
nith=self.table.item(9,3).text()
nifo=self.table.item(9,4).text()
nifi=self.table.item(9,5).text()
self.questions = pd.DataFrame({'Question': [zeze,onze ,twze ,thze ,foze ,fize ,size ,seze ,eize ,nize],
'Option1': [zeon,onon ,twon ,thon ,foon ,fion ,sion ,seon ,eion ,nion],
'Option2': [zetw,ontw ,twtw ,thtw ,fotw ,fitw ,sitw ,setw ,eitw ,nitw],
'Option3': [zeth,onth ,twth ,thth ,foth ,fith ,sith ,seth ,eith ,nith],
'Option4': [zefo,onfo ,twfo ,thfo ,fofo ,fifo ,sifo ,sefo ,eifo ,nifo],
'Correct Answer': [zefi,onfi ,twfi ,thfi ,fofi ,fifi ,sifi ,sefi ,eifi ,nifi]})
teacherquestions.close()
teacherquiz.show()
m = makequestions()
choosefrom=[]
for i in range(1,101):
choosefrom.append(["t",i])
random_name=random.choice(choosefrom)
frame=m.questions
When I run this code I get the error:
File "c:\Users\santh\OneDrive\Documents\PyQt5\yeah - Copy.py", line 481, in frame=m.questions AttributeError: 'makequestions' object has no attribute 'questions'
Solution 1:[1]
Try to add/declare property questions in your class __init__
method, smth like:
class MakeQuestions(QMainWindow):
def __init__(self):
self.questions = None
super(MakeQuestions, self).__init__()
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kuro Neko |