PyQt6 中QMessageBox 弹窗最新用法,解决PyQt5中MessageBox.Yes|MessageBox.No不能使用的问题

PyQt6 更新了PyQt5 MessageBox的用法,我在使用的时候发现,PyQt6没有MessageBox.YesMessageBox.No的用法

我在查看了弹窗返回的内容时发现,当点击按钮Yes的时候,返回回来的是<enum StanderButton.Yes>
无法完成判断的需求,我想到一个解决的方法是,将返回来的内容直接变成字符串的方式,再if判断执行就行了
我之前的代码和结果:

try:
            reply = QMessageBox.question(self, '信息提示', '确定删除内容?')
            #reply = str(reply)
            print(reply)
            print(type(reply))
            if reply == 'StandardButton.Yes':
                del_row_sql = f'delete from integral_db where id={id}'
                cur.execute(del_row_sql)
                conn.commit()
            else:
                return
        except Exception as e:
            print(e)

在这里插入图片描述
输出结果:
在这里插入图片描述

我之后的代码和结果:

        try:
            reply = QMessageBox.question(self, '信息提示', '确定删除内容?')
            reply = str(reply)
            print(reply)
            print(type(reply))
            if reply == 'StandardButton.Yes':
                del_row_sql = f'delete from integral_db where id={id}'
                cur.execute(del_row_sql)
                conn.commit()
            else:
                return
        except Exception as e:
            print(e)

总结:最关键的问题是改变返回结果的字符类型,再判断就OK了

有啥不明白的,欢迎留言!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值