按钮单击后显示对话框

问题描述 投票:0回答:1

我一直在关注本教程:https://www.blog.pythonlibrary.org/2013/04/16/pyside-standard-dialogs-and-message-boxes/,以便在单击对话框后让我的一个按钮显示通知消息框。问题是代码根本不显示对话框。这是我的代码,包括我到目前为止所尝试的内容以及堆栈跟踪。

# parsing Information Message Dialog
    def data_parsed_notification(self):
            """
            Show the information message
        """
            QtGui.QMessageBox.information(self, "Information", "Data Has Been Parsed!")


    # Data Parsing Functions!!!

    # Canonical Addresses button function
    def select_canonical_data(self):
        os.system('CanonicalAddressesParser.py')
        self.generate_canonical_report.setEnabled(True)
        self.canonicalAddressesButton.clicked.connect(self.data_parsed_notification())

堆栈跟踪

QtGui.QMessageBox.information(self, "Information", "Data Has Been Parsed!")
AttributeError: 'module' object has no attribute 'QMessageBox'

现在代码

# Data Parsed Dialog Box
    def data_parsed_notification(self):
        msgBox = QtWidgets.QMessageBox(self)
        msgBox.setWindowTitle('Information')
        msgBox.setIcon(QtWidgets.QMessageBox.Information)
        msgBox.setText('Data Has Been Parsed!')
        msgBox.show()

    # Canonical Addresses button function
    def select_canonical_data(self):
        os.system('CanonicalAddressesParser.py')
        self.generate_canonical_report.setEnabled(True)
        self.canonicalAddressesButton.clicked.connect(self.data_parsed_notification())


Stack Trace 

TypeError: arguments did not match any overloaded call:
  QMessageBox(QWidget parent=None): argument 1 has unexpected type 'Ui_MainWindow'
  QMessageBox(QMessageBox.Icon, str, str, QMessageBox.StandardButtons buttons=QMessageBox.NoButton, QWidget parent=None, Qt.WindowFlags flags=Qt.Dialog|Qt.MSWindowsFixedSizeDialogHint): argument 1 has unexpected type 'Ui_MainWindow'
python pyqt
1个回答
0
投票

尝试下面的代码,它将适合您。

self.canonicalAddressesButton.clicked.connect(self.data_parsed_notification)

def data_parsed_notification(self):
    msgBox = QtWidgets.QMessageBox()
    msgBox.information(self, Message', 'Data Has Been Parsed!')
© www.soinside.com 2019 - 2024. All rights reserved.