【发布时间】:2019-01-30 18:49:16
【问题描述】:
当用户在 PyQT5-GUI 应用程序中提交空白或不正确的信息作为用户名和密码时,我想向用户显示弹出信息/警告/等消息。
我很困惑,我不知道问题的根本原因在哪里。
Windows 10 - 64 位 ___ Python 3.6 和 3.7 - 64 位 ____ PyQT5 - 5.11.3
class Ui_MainWindow(object):
def __init__(self):
<skipped>
self.btn_signin.clicked.connect(self.check_userPass) #### User/Pass checking.
<skipped>
def check_userPass(self): # an internal method/function from `Ui_MainWindow`.
username = self.txt_user.text() #a QlineEdit
password = self.txt_pass.text() #a QlineEdit
if len(username) < 2 and len(password) < 2:
QtWidgets.QMessageBox.question(self, "Checkk", "Helllooo", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel)
###error for above line:
##Traceback (most recent call last):
## File ".\demo_codes.py", line 215, in check_userPass
## QtWidgets.QMessageBox.question(self, 'List manipulation', "Helllooo", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
##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 'Ui_MainWindow'
QtWidgets.QMessageBox.question("Checkk", "Helllooo", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel)
###error for above line:
##Traceback (most recent call last):
## File ".\demo_codes.py", line 215, in check_userPass
## QtWidgets.QMessageBox.question('List manipulation', "Helllooo", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
##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 'str'
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
#ui.setupUi(MainWindow) # i renamed `setupUi` to __init__.
MainWindow.show()
sys.exit(app.exec_())
【问题讨论】:
标签: python-3.x windows pyqt5 qt-designer