python - PyQt messagebox yes or no with an if

标签 python pyqt4

伙计们。我想做的是,询问用户是否想要重置表单值。 如果是,则重置,如果不是,弹出消息框。信息以确认没有发生任何事情。

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/

相关文章:

python - 从 appengine 应用上传文件到谷歌云存储

python - 将颜色图添加到图表中

python - 推出Python项目

python - 从 Qt Designer 和 PyQt 开始

Python 找不到 Blender 模块

python - OpenCV 2.4.0 python 绑定(bind)中的 ORB

python - 为什么 ActivePython 存在?

python - 我的线程正确吗?如果是,那么为什么代码不起作用?

python-2.7 - PyQt 4 : Get Position of Toolbar

python - 使用QAbstractTableModel(模型/ View )时如何将 "Select one..."添加到QComboBox?