QMessageBox不会关闭



我对Python和PyQt5比较陌生,所以很抱歉,如果这个问题很简单。我想创建一个关键消息,指出特定的QlineEdit为空,因此程序无法运行。我能够将消息绑定到相应的输入,但是,当我单击取消按钮或"X"时,消息不断弹出。我希望它在单击任一后关闭,我做错了什么?PS:我正在使用 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')          
# Enable and disable the start button    
self.start_btn.setEnabled(False)
def enablebtn(self):
if (len(self.Radius_in.text()) != 0) and (len(self.Distance_in.text()) != 0) and (len(self.Speed_in.text()) != 0)
and (len(self.Nload_in.text()) != 0) and (len(self.Acq_int_in.text()) != 0) and (len(self.file_name.text()) != 0): 
self.start_btn.setEnabled(True)
else:
self.start_btn.setEnabled(False)

相关内容

  • 没有找到相关文章

最新更新