I created a class of MainWindow and a class of FirstParty which is a second form. I created a object of FirstParty with the name of firstPartyForm in MainWindow class but when i run my program it shows that the firstPartyForm is not defined do you mean FirstParty.
class Mainwindow(QMainWindow):
def __init__(self):
super(Mainwindow,self).__init__()
loadUi("Part1.ui",self)
#These 2 lines are used to put funnctions on close and minimize buttons.
#self.MinimizeButton.clicked.connect(lambda: self.showMinimized())
#self.CrossButton.clicked.connect(lambda: self.close())
districts = ["Attock","Bahawalnagar","Bahawalpur","Bhakkar","Chakwal","Chiniot","Dera Ghazi Khan","Faislabad","Gujranwala","Gujrat","Hafizabad","Jehlam","Jhang","Kasur","Khanewal","khusab","Lahore","Layyah","Lodhran","Mandi Bahauddin","Mian Wali","Multan","Muzaffarabad","NankanaSab","Narowal","Okara","Pakpattan","Raheem Yar Khan","Rajanpur","Rawalpindi","Sahiwal","Sarghoda","Sheikhupura","Sialkot","Toba Tek Singh","Vehari"]
print(len(districts))
tehsils = Import2dFile("Tehsils.txt")
print(tehsils)
self.cmb_District.addItems(districts)
def createFirstPartyForm():
global firstPartyForm
firstPartyForm = FirstParty()
print(firstPartyForm.checkBox.text())
firstPartyForm.show()
#return firstPartyForm
if self.cmb_District.currentText() == "Lahore":
print("ls")
print(str(self.cmb_District.currentText()))
self.cmb_Tehsil.addItems(tehsils)
self.firstParty.clicked.connect(createFirstPartyForm)
first_party_data = firstPartyForm.buttonBox.clicked.connect(self.the_first_party_ok_button_was_clicked)
def the_first_party_ok_button_was_clicked():
first_party_data = firstPartyForm.isBothCheckBoxTick(firstPartyForm)
return first_party_data
print(first_party_data)
class FirstParty(QDialog):
def __init__(self):
super(FirstParty, self).__init__()
loadUi("AddFirstParty.ui",self)
name = self.lineEdit.text()
cnic = self.lineEdit_2.text()
Relation = self.comboBox.currentText()
relationText = self.lineEdit_4.text()
contact_no = self.lineEdit_5.text()
email = self.lineEdit_6.text()
address = self.lineEdit_7.text()
def isBothCheckBoxTick(self):
btn1 = self.stateChanged(self.checkBox.text())
btn2 = self.stateChanged(self.checkBox_2.text())
if btn1 == "checked" and btn2 == "checked":
FirstPartyRecord = [self.name,self.cnic,self.Relation,self.relationText,self.contact_no,self.email,self.address]
return FirstPartyRecord
return None
def stateChanged(self,button):
if button == "Use This First Party in the Form":
if self.checkBox.isChecked():
return "checked"
else:
return "unchecked"
elif button == "Through Power of Attorney":
if self.checkBox_2.isChecked():
return "checked"
else:
return "unchecked"
It is Line no 24 where i am using it
CodePudding user response:
I think it is because you are not using self with firstPartyForm. Try self.firstPartyForm
CodePudding user response:
check your AddFirstParty.ui file, probably there is no firstPartyForm name