Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt messagebox yes or no with an if

Tags:

python

pyqt4

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.

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? Thanx

like image 388
Tian Avatar asked Dec 13 '15 16:12

Tian


1 Answers

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!

like image 171
cdonts Avatar answered Oct 21 '22 06:10

cdonts