请写一个采用pyqt技术的登录验证程序
时间: 2023-04-04 13:03:20 浏览: 83
好的,我可以回答这个问题。以下是一个采用pyqt技术的登录验证程序的示例代码:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton
class Login(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('登录验证程序')
self.setGeometry(300, 300, 300, 200)
self.label_username = QLabel('用户名:', self)
self.label_username.move(50, 30)
self.label_password = QLabel('密码:', self)
self.label_password.move(50, 70)
self.edit_username = QLineEdit(self)
self.edit_username.move(110, 30)
self.edit_password = QLineEdit(self)
self.edit_password.move(110, 70)
self.edit_password.setEchoMode(QLineEdit.Password)
self.button_login = QPushButton('登录', self)
self.button_login.move(110, 110)
self.button_login.clicked.connect(self.login)
self.show()
def login(self):
username = self.edit_username.text()
password = self.edit_password.text()
if username == 'admin' and password == '123456':
print('登录成功')
else:
print('用户名或密码错误')
if __name__ == '__main__':
app = QApplication(sys.argv)
login = Login()
sys.exit(app.exec_())
```
这个程序包含一个窗口,其中有两个文本框和一个按钮。用户输入用户名和密码,然后点击登录按钮。如果用户名和密码正确,程序会输出“登录成功”,否则会输出“用户名或密码错误”。