QMessageBox.warning(self,'错误', '用户名和密码不匹配', QMessageBox.Yes, QMessageBox.Yes)
以上一条语句输出,但更改前这样显示的,中英文混合,看着别扭。
参考了http://srinikom.github.io/pyside-docs/PySide/QtGui/QMessageBox.html上的文档
self.box = QMessageBox(QMessageBox.Warning, "错误", "用户名和密码不匹配!")
self.box.addButton(self.tr("确定"), QMessageBox.YesRole)
#self.box.addButton(self.tr("取消"), QMessageBox.NoRole)
self.box.show()
self.box = QMessageBox(QMessageBox.Warning, "错误", "用户名和密码不匹配!") qyes=self.box.addButton(self.tr("确定"), QMessageBox.YesRole) qno=self.box.addButton(self.tr("取消"), QMessageBox.NoRole) self.box.exec_() if self.box.clickedButton() == qyes: print('okokok') else: return
其中,参数QMessageBox.YesRole可以为以下几种:
QMessageBox.InvalidRole | The button is invalid. |
QMessageBox.AcceptRole | Clicking the button causes the dialog to be accepted (e.g. OK). |
QMessageBox.RejectRole | Clicking the button causes the dialog to be rejected (e.g. Cancel). |
QMessageBox.DestructiveRole | Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog. |
QMessageBox.ActionRole | Clicking the button causes changes to the elements within the dialog. |
QMessageBox.HelpRole | The button can be clicked to request help. |
QMessageBox.YesRole | The button is a “Yes”-like button. |
QMessageBox.NoRole | The button is a “No”-like button. |
QMessageBox.ApplyRole | The button applies current changes. |
QMessageBox.ResetRole | The button resets the dialog’s fields to default values. |