pyqt QMessageBox按钮中文显示

pyqt QMessageBox 所带的按钮是英文 在写中文软件上面看着好烦人,

研究了一下 找到了 显示中文按钮的方法

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMessageBox, QLineEdit, QWidget, QCheckBox, QPushButton, QHBoxLayout
from enum import Enum

mesboxtype = [
    QMessageBox.NoIcon,
    QMessageBox.Information,
    QMessageBox.Warning,
    QMessageBox.Critical,
    QMessageBox.Question]


class mesbox_base(object):
    none = 0
    info = 1
    waring = 2
    err = 3
    question = 4

    def btn_one(self, icontype, showmes, titelmes='提示框', icon='./data/logo.ico'):
        '''
        单按钮对话框 \n
        icontype
        none = 0
        info = 1
        waring = 2
        err = 3
        question = 4
        showmes 显示信息
        '''
        re = QMessageBox(
            mesboxtype[icontype], titelmes, showmes)
        re.setWindowIcon(QIcon(icon))
        ye = re.addButton('确定', QMessageBox.YesRole)
        re.exec_()

    def btn_two(self, icontype, showmes, titelmes='提示框', icon='./data/logo.ico'):
        '''
        双按钮对话框 \n
        icontype
        none = 0
        info = 1
        waring = 2
        err = 3
        question = 4
        showmes 显示信息
        '''
        re = QMessageBox(
            mesboxtype[icontype], titelmes, showmes)
        re.setWindowIcon(QIcon(icon))
        btn_ok = re.addButton('确定', QMessageBox.YesRole)
        btn_no = re.addButton('取消', QMessageBox.NoRole)
        re.exec_()
        return re.clickedButton() == btn_ok

实例化类 调用方法就能使用了

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值