吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2038|回复: 3
收起左侧

[求助] 关于QMessageBox报错的问题

[复制链接]
少艾 发表于 2020-9-16 13:25
想使用QMessageBox实现提示弹窗得功能,只要点击按钮,就会出现提示。但是代码报错了,好像是说QMessageBox的使用格式有问题?但是查了一下没啥问题啊,在网上也搜了很久,相关的信息太少了,所以只能发个求助帖了,希望各位帮忙解决一下。
报错如下,因为太长了,不太好截图所以就只能复制了。
download_warning = QMessageBox.question(self, "确认下载", '确定下载文件到路径中吗?',
TypeError: question(QWidget, str, str, buttons: Union[QMessageBox.StandardButtons, QMessageBox.StandardButton] = QMessageBox.StandardButtons(QMessageBox.Yes|QMessageBox.No), defaultButton: QMessageBox.StandardButton = QMessageBox.NoButton): argument 1 has unexpected type 'My_Window'

代码如下
[Python] 纯文本查看 复制代码
from PySide2.QtWidgets import QApplication, QMessageBox
from PySide2.QtUiTools import QUiLoader
from PySide2 import QtXml
from PySide2 import QtWidgets
from PyQt5.QtWidgets import *
import sys

class My_Window():
    def __init__(self):
        self.ui = QUiLoader().load('demo.ui')
        self.ui.pushButton.clicked.connect(lambda :self.box(self.ui.pushButton))

    def box(self, btn):
        if btn.text() == '对话框':
           download_warning = QMessageBox.question(self, "确认下载", '确定下载文件到路径中吗?',
                                            QMessageBox.Yes|QMessageBox.No, QMessageBox.Yes)
           if download_warning == QMessageBox.Yes:
               print(download_warning)


if __name__ == "__main__":
    app = QApplication([])
    window = My_Window()
    window.ui.show()
    sys.exit(app.exec_())

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 少艾 发表于 2020-9-16 13:27
程序可以运行,但是点击yes或者no之后就会报错
JuncoJet 发表于 2020-9-16 14:51
应该不是你写的问题,学习Qt一个星期,发现Qt有种机制,当当前窗口是唯一窗口时你关闭,会退出程序
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);

C++的代码,Python自己百度
 楼主| 少艾 发表于 2020-9-16 18:25
JuncoJet 发表于 2020-9-16 14:51
应该不是你写的问题,学习Qt一个星期,发现Qt有种机制,当当前窗口是唯一窗口时你关闭,会退出程序
    QA ...

好的,我去查查
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-19 21:57

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表