PyQt5实现登录页面

所属分类: 脚本专栏 / python 阅读数: 297
收藏 0 赞 0 分享

本文实例为大家分享了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()
    led_workerid.setFixedWidth(270)
    led_workerid.setFixedHeight(38)
 
    lbl_pwd = QLabel("密码")
    lbl_pwd.setFont(QFont("Microsoft YaHei"))
    led_pwd = QLineEdit()
    led_pwd.setEchoMode(QLineEdit.Password)
    led_pwd.setFixedWidth(270)
    led_pwd.setFixedHeight(38)
 
    btn_login = QPushButton("登录")
    btn_login.setFixedWidth(270)
    btn_login.setFixedHeight(40)
    btn_login.setFont(QFont("Microsoft YaHei"))
    btn_login.setObjectName("login_btn")
    btn_login.setStyleSheet("#login_btn{background-color:#2c7adf;color:#fff;border:none;border-radius:4px;}")
 
    fmlayout.addRow(lbl_workerid, led_workerid)
    fmlayout.addRow(lbl_pwd, led_pwd)
    fmlayout.addWidget(btn_login)
    hbox.setAlignment(Qt.AlignCenter)
    # 调整间距
    fmlayout.setHorizontalSpacing(20)
    fmlayout.setVerticalSpacing(12)
 
    hbox.addLayout(fmlayout, 2)
 
    login_widget.setLayout(hbox)
 
    self.center()
    self.show()
 
  def center(self):
    qr = self.frameGeometry()
    cp = QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())
 
 
if __name__ == "__main__":
  app = QApplication(sys.argv)
  ex = LoginForm()
  sys.exit(app.exec_())

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

pandas的qcut()方法详解

这篇文章主要介绍了pandas的qcut()方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

从列表或字典创建Pandas的DataFrame对象的方法

这篇文章主要介绍了从列表或字典创建Pandas的DataFrame对象的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

pandas.DataFrame的pivot()和unstack()实现行转列

这篇文章主要介绍了pandas.DataFrame的pivot()和unstack()实现行转列,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

pandas中的series数据类型详解

这篇文章主要介绍了pandas中的series数据类型详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

pandas 时间格式转换的实现

这篇文章主要介绍了pandas 时间格式转换的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

python中时间、日期、时间戳的转换的实现方法

这篇文章主要介绍了python中时间、日期、时间戳的转换的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

pandas进行时间数据的转换和计算时间差并提取年月日

这篇文章主要介绍了pandas进行时间数据的转换和计算时间差并提取年月日,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

详解将Pandas中的DataFrame类型转换成Numpy中array类型的三种方法

这篇文章主要介绍了详解将Pandas中的DataFrame类型转换成Numpy中array类型的三种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

python和c语言的主要区别总结

在本篇文章里小编给各位整理了关于python和c语言的主要区别的相关知识帖内容,有需要的朋友们学习阅读下。
收藏 0 赞 0 分享

选择Python写网络爬虫的优势和理由

在本篇文章里小编给各位整理了一篇关于选择Python写网络爬虫的优势和理由以及相关代码实例,有兴趣的朋友们阅读下吧。
收藏 0 赞 0 分享
查看更多