伙计们。我想做的是,询问用户是否想要重置表单值。 如果是,则重置,如果不是,弹出消息框。信息以确认没有发生任何事情。
def reset(self):
qm = QtGui.QMessageBox
qm.question(self,'', "Are you sure to reset all the values?", qm.Yes | qm.No)
if qm.Yes:
self.price_box.setText("0")
self.results_tax.setText("")
self.results_window.setText("")
self.tax_rate.setValue(21)
else:
qm.information(self,'',"Nothing Changed")
但是现在,无论我选择什么,表格总是会被重置。 我的 if 语句有什么问题吗? 谢谢
最佳答案
应该是:
ret = qm.question(self,'', "Are you sure to reset all the values?", qm.Yes | qm.No)
if ret == qm.Yes:
希望对您有所帮助!
关于python - PyQt messagebox yes or no with an if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253350/