PyQt5实现登录页面实现登录页面
本文实例为大家分享了PyQt5实现登录页面的具体代码,供大家参考,具体内容如下
效果图:
python代码:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QPainter, QColor, QFont, QIcon
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel, QDesktopWidget, QHBoxLayout,
QFormLayout, \
QPushButton, QLineEdit
class LoginForm(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
"""
初始化UI
:return:
"""
self.setObjectName("loginWindow")
self.setStyleSheet('#loginWindow{background-color:white}')
self.setFixedSize(650, 400)
self.setWindowTitle("登录")
self.setWindowIcon(QIcon('static/logo_title.png'))
self.text = "xxxx消息盒子用户登录"
# 添加顶部logo图片
pixmap = QPixmap("static/logo_header.png")
scaredPixmap = pixmap.scaled(650, 140)
label = QLabel(self)
label.setPixmap(scaredPixmap)
# 绘制顶部文字
lbl_logo = QLabel(self)
lbl_logo.setText(self.text)
lbl_logo.setStyleSheet("QWidget{color:white;font-weight:600;background: transparent;font-size:30px;}")
lbl_logo.setFont(QFont("Microsoft YaHei"))
lbl_logo.move(150, 50)
lbl_logo.setAlignment(Qt.AlignCenter)
lbl_logo.raise_()
# 登录表单内容部分
login_widget = QWidget(self)
login_widget.move(0, 140)
login_widget.setGeometry(0, 140, 650, 260)
hbox = QHBoxLayout()
# 添加左侧logo
logolb = QLabel(self)
logopix = QPixmap("static/logo.png")
logopix_scared = logopix.scaled(100, 100)
logolb.setPixmap(logopix_scared)
logolb.setAlignment(Qt.AlignCenter)
hbox.addWidget(logolb, 1)
# 添加右侧表单
fmlayout = QFormLayout()
lbl_workerid = QLabel("用户名")
lbl_workerid.setFont(QFont("Microsoft YaHei"))
led_workerid = QLineEdit()
评论0