用python写一个可视化的登陆界面
时间: 2023-06-19 14:09:17 浏览: 136
以下是一个简单的登陆界面的Python代码,使用了PyQt5库实现可视化界面:
```python
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout
from PyQt5.QtGui import QIcon
class Login(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Login')
self.setWindowIcon(QIcon('icon.png'))
self.setGeometry(300, 300, 250, 150)
self.label_user = QLabel()
self.label_user.setText('Username:')
self.label_pass = QLabel()
self.label_pass.setText('Password:')
self.input_user = QLineEdit()
self.input_pass = QLineEdit()
self.input_pass.setEchoMode(QLineEdit.Password)
self.button_login = QPushButton()
self.button_login.setText('Login')
self.button_login.clicked.connect(self.login)
layout = QVBoxLayout()
layout.addWidget(self.label_user)
layout.addWidget(self.input_user)
layout.addWidget(self.label_pass)
layout.addWidget(self.input_pass)
layout.addWidget(self.button_login)
self.setLayout(layout)
def login(self):
# 在这里编写登录逻辑
pass
if __name__ == '__main__':
app = QApplication([])
login = Login()
login.show()
app.exec_()
```
这个登陆界面包含了两个输入框(用户名和密码)和一个登陆按钮。当用户点击登陆按钮时,我们可以在 `login` 方法中编写相应的登陆逻辑。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)