本文实例为大家分享了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_())
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
PyQt5,登录页面
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“PyQt5实现登录页面”评论...
更新日志
2024年10月07日
2024年10月07日
- 《丁当 20首重量级歌曲 Fu Good 下一站天后 2CD》[WAV/分轨][650MB]
- 歌莉雅.2012-My.Voice.Story【环星】【FLAC分轨】
- 群星.1993-一曲成名·青春无悔【飞碟】【WAV+CUE】
- 刘德华.2000-爱无知(金装版)【NEWMELODY】【WAV+CUE】
- 许巍《时光漫步》1CD[FLAC/分轨][804.3MB]
- 群星《2024第一季度百度歌曲排行抖音榜top100》1CD[FLAC/分轨][2.3GB]
- 张柏芝《全新经验》[FLAC/分轨][450MB]
- 唐朝.2008-浪漫骑士【音乐家】【WAV+CUE】
- 张芸京.2016-失败的高歌【泡耳音乐】【WAV+CUE】
- 群星.1991-音乐工厂1·皇后大道东【音乐工厂】【WAV+CUE】
- 群星.1992-音乐工厂2·首都【音乐工厂】【WAV+CUE】
- 群星.1994-音乐工厂3·儿童乐园【音乐工厂】【WAV+CUE】
- 胡鸿钧.2021-ex:CHANGE【星梦娱乐】【WAV+CUE】
- 班得瑞原装进口《第一张新世纪专辑:仙境》1CD[APE/CUE分轨][292.3MB]
- 伍佰《摇滚教父 伍佰黄金精选 2CD》[WAV+CUE][990MB]