【发布时间】:2023-03-23 17:21:02
【问题描述】:
我是 Python 3.8 和 PyQT5 的新手,我正在尝试使用 GUI 制作应用程序。
我创建了一个带有两个 QLineEdit(用户和密码)的登录表单。一旦用户单击“登录”按钮,我想检查用户作为用户/密码输入的内容是否在使用其他文件中的函数在数据库中。我为表单创建的类与下一个类似:
# Where the check function for the password is
from CLBK_CheckPassword import CheckPassword
from PyQt5 import QtWidgets
class W_Password(QtWidgets.QWidget):
def __init__(self, App):
super(W_Password,self).__init__()
# Set the window title and size
WindowHeight = 400
WindowWeight = WindowHeight/3
self.setWindowTitle("Login Window")
self.resize(WindowHeight,WindowWeight)
# Text box
self.Input_User = QtWidgets.QLineEdit()
self.Input_Password = QtWidgets.QLineEdit()
self.Input_Password.setEchoMode(QtWidgets.QLineEdit.Password)
# Button
self.Button_Login = QtWidgets.QPushButton("Login")
self.Button_Login.clicked.connect(CheckPassword())
# Layout and items positioning
self.Layout = QtWidgets.QGridLayout(self)
self.Layout.addWidget(self.Button_Login,3,2,1,2)
self.Layout.addWidget(self.Label_User,0,0,1,1)
self.Layout.addWidget(self.Input_User,0,1,1,3)
self.Layout.addWidget(self.Label_Password,1,0,1,1)
self.Layout.addWidget(self.Input_Password,1,1,1,3)
这段代码有两个问题:
- 创建并显示表单后,会自动执行“CheckPassword()”函数(仅当用户按下按钮时才会执行)。
- 第二个问题是函数执行后出现以下错误:TypeError: argument 1 has unexpected type 'NoneType'
【问题讨论】:
标签: python python-3.x pyqt pyqt5