简体   繁体   English

PyQt messagebox yes或no with if

[英]PyQt messagebox yes or no with an if

So guys.What I want to do is, ask if user wanted to reset the form values. 所以伙计。我想做的是,询问用户是否想要重置表单值。 If yes, reset, if no, popup a messagebox.information to confirm nothing happened. 如果是,则重置,如果不是,则弹出messagebox.information以确认没有发生任何事情。

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")

But for now, No matter what I choose, the form always got reseted. 但就目前而言,无论我选择什么,形式总是被重置。 Anything wrong with my if statement? 我的if语句有什么问题吗? Thanx 感谢名单

It should be: 它应该是:

ret = qm.question(self,'', "Are you sure to reset all the values?", qm.Yes | qm.No)

if ret == qm.Yes:

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM