按钮单击后显示对话框
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了按钮单击后显示对话框相关的知识,希望对你有一定的参考价值。
我一直在关注本教程: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'
答案
尝试下面的代码,它将适合您。
self.canonicalAddressesButton.clicked.connect(self.data_parsed_notification)
def data_parsed_notification(self):
msgBox = QtWidgets.QMessageBox()
msgBox.information(self, Message', 'Data Has Been Parsed!')
以上是关于按钮单击后显示对话框的主要内容,如果未能解决你的问题,请参考以下文章