PyQT中让QMessageBox按钮显示中文

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.


  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值