I am relatively new to Python and PyQt5, so sorry if this question is quite simple. I want to create a critical message stating that a particular QlineEdit is empty and so the program does not run. I was able to bind the message to the respective input, however, when I click the cancel button or the 'X' the message keeps popping. I would like it to close after either is clicked, what am I doing wrong? PS: I am using PyQt5.
def startTest(self):
if len(self.Radius_in.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the radius", QMessageBox.Cancel)
pass
elif len(self.Distance_in.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the distance",QMessageBox.Cancel)
pass
elif len(self.Speed_in.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the linear speed",QMessageBox.Cancel)
pass
elif len(self.Nload_in.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the normal load",QMessageBox.Cancel)
pass
elif len(self.Acq_int_in.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the acquisition rate",QMessageBox.Cancel)
pass
elif len(self.file_name.text()) == 0:
QMessageBox.critical(self, "Error", "Please enter the name of the file",QMessageBox.Cancel)
pass
else:
#open and save a file
fileName = self.file_name.text()
savedFile = open(fileName + ".txt","w")
runTime = round(float(str(self.Distance_in.text()))/(60.*float(str(self.Speed_in.text()))),2)
NoLaps = round(float(str(self.Distance_in.text()))/(pi*2.*float(str(self.Radius_in.text()))),2)
discRot = round(float(str(self.Speed_in.text()))*60./(2.*pi*float(str(self.Radius_in.text()))),2)
discFreq = round(float(str(self.Speed_in.text()))/(2.*pi*float(str(self.Radius_in.text()))),2)
try:
self.duration_out.setText(str(runTime))
self.laps_out.setText(str(NoLaps))
self.rotation_out.setText(str(discRot))
self.Freq_out.setText(str(discFreq))
except:
self.duration_out.setText('error')
self.laps_out.setText('error')
self.rotation_out.setText('error')
self.Freq_out.setText('error')