PyQT中让QMessageBox按钮显示中文

来源:互联网 发布:c语言怎么产生随机数 编辑:程序博客网 时间:2024/05/16 16:11

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.InvalidRoleThe button is invalid.QMessageBox.AcceptRoleClicking the button causes the dialog to be accepted (e.g. OK).QMessageBox.RejectRoleClicking the button causes the dialog to be rejected (e.g. Cancel).QMessageBox.DestructiveRoleClicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.QMessageBox.ActionRoleClicking the button causes changes to the elements within the dialog.QMessageBox.HelpRoleThe button can be clicked to request help.QMessageBox.YesRoleThe button is a “Yes”-like button.QMessageBox.NoRoleThe button is a “No”-like button.QMessageBox.ApplyRoleThe button applies current changes.QMessageBox.ResetRoleThe button resets the dialog’s fields to default values.

 
阅读全文
1 0
原创粉丝点击