用pyqt5写一个蓝色背景的登陆界面
时间: 2023-05-15 17:05:13 浏览: 55
可以使用以下代码实现:
```python
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton
from PyQt5.QtGui import QIcon, QPixmap, QFont
from PyQt5.QtCore import Qt
class Login(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setFixedSize(400, 300)
self.setWindowTitle('Login')
self.setWindowIcon(QIcon('icon.png'))
# 设置背景颜色
self.setStyleSheet('background-color: #0072C6;')
# 设置标题
title = QLabel(self)
title.setText('Login')
title.setFont(QFont('Arial', 20))
title.setAlignment(Qt.AlignCenter)
title.setGeometry(0, 50, 400, 50)
# 设置用户名和密码输入框
username_label = QLabel(self)
username_label.setText('Username:')
username_label.setFont(QFont('Arial', 12))
username_label.setStyleSheet('color: white;')
username_label.setGeometry(50, 120, 100, 30)
self.username_edit = QLineEdit(self)
self.username_edit.setGeometry(150, 120, 200, 30)
password_label = QLabel(self)
password_label.setText('Password:')
password_label.setFont(QFont('Arial', 12))
password_label.setStyleSheet('color: white;')
password_label.setGeometry(50, 170, 100, 30)
self.password_edit = QLineEdit(self)
self.password_edit.setGeometry(150, 170, 200, 30)
self.password_edit.setEchoMode(QLineEdit.Password)
# 设置登录按钮
login_button = QPushButton(self)
login_button.setText('Login')
login_button.setFont(QFont('Arial', 12))
login_button.setGeometry(150, 230, 100, 30)
login_button.clicked.connect(self.login)
# 显示窗口
self.show()
def login(self):
username = self.username_edit.text()
password = self.password_edit.text()
# TODO: 实现登录逻辑
if __name__ == '__main__':
app = QApplication([])
login = Login()
app.exec_()
```
这是一个使用 PyQt5 实现的简单的登录界面,背景颜色为蓝色。界面包含用户名和密码输入框以及登录按钮。在点击登录按钮时,可以获取用户名和密码,并实现登录逻辑。