临门一脚,QMessageBox.critical为什么不正常工作
------------------------main.py----------------------------import sys
from PySide6.QtWidgets import QApplication,QMainWindow,QWidget,QDialog,QMessageBox
from PyQt6.QtCore import Qt
import Login
import HSJCQueryWindow
import Dbconnect
# 创建Login类继承HSJCQueryWindow里面全部内容
class HSJCQueryWindow(HSJCQueryWindow.Ui_MainWindow, QMainWindow):
def __init__(self):
super(HSJCQueryWindow, self).__init__()
self.setupUi(self)
class Login(Login.Ui_MainWindow, QMainWindow):
def __init__(self):
super(Login, self).__init__()
self.setupUi(self)
# 登录验证
def login_check():
username = login.UserNameEdit.text() #获取Login.py里的用户名值
password = login.PasswordEdit.text() #获取Login.py里的密码值
sql = "SELECT user_name,COMM.F_DESCRIPT(password) FROM staff_dict WHERE user_name = '{uname}' ".format(uname=username)
Dbconnect.cursor.execute(sql)
results = Dbconnect.cursor.fetchall()
for r in results:
if (username==" "):
QMessageBox.critical(login,title='注意',text='用户名不能为空',button0='OK',button1='退出')
else:
if (r==password):
hsjc_query_window.show()
else:
QMessageBox.critical(login,title='注意',text='用户名或密码错误',button0='OK',button1='退出')
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
# 为Login类和HSJCQueryWindow类实例化对象
login = Login()
hsjc_query_window = HSJCQueryWindow()
# 显示登陆窗口
login.setupUi(window)
window.show()
# 将login_check函数与登录按钮绑定
login.LoginButton.clicked.connect(login_check)
sys.exit(app.exec())
数据库通,sql语句也通,断点设置后输出的r密码也正常
if (r==password): 是可以正常跳转窗体的
但是我调试时故意输错密码,最初代码为QMessageBox.critical(login,'注意','用户名或密码错误'),时Login.MainWindow就(未响应),消息框也不弹出来
然后我按格式把参数写全QMessageBox.critical(login,title='注意',text='用户名或密码错误',button0='OK',button1='退出'),调试就报错
TypeError: PySide6.QtWidgets.QMessageBox.critical(): not enough arguments
搜了网上,我参数应该写全了啊。请问大神们是什么回事,可以教教我QMessageBox该怎么正确书写吗
页:
[1]