PyQt5實現(xiàn)登錄頁面
更新時間:2020年05月30日 10:34:26 作者:xiaopengyaonixi
這篇文章主要為大家詳細介紹了PyQt5實現(xiàn)登錄頁面,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了PyQt5實現(xiàn)登錄頁面的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:
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_() # 登錄表單內(nèi)容部分 login_widget = QWidget(self) login_widget.move(0, 140) login_widget.setGeometry(0, 140, 650, 260) hbox = QHBoxLayout() # 添加左側(cè)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) # 添加右側(cè)表單 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) # 調(diào)整間距 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_())
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Pytorch上下采樣函數(shù)之F.interpolate數(shù)組采樣操作詳解
最近用到了上采樣下采樣操作,pytorch中使用interpolate可以很輕松的完成,下面這篇文章主要給大家介紹了關(guān)于Pytorch上下采樣函數(shù)之F.interpolate數(shù)組采樣操作的相關(guān)資料,需要的朋友可以參考下2022-04-04Python爬蟲之自動爬取某車之家各車銷售數(shù)據(jù)
應朋友要求,幫忙采集某車之家的一些汽車品牌的銷售數(shù)據(jù),包含購車時間、車型、經(jīng)銷商、裸車價等一類信息. 今天我們就簡單演示一下采集過程,大家可以根據(jù)自己的興趣進行拓展.比如采集自己喜歡的品牌汽車數(shù)據(jù)進行統(tǒng)計分析等等,需要的朋友可以參考下2021-06-06Python3 ffmpeg視頻轉(zhuǎn)換工具使用方法解析
這篇文章主要介紹了Python3 ffmpeg視頻轉(zhuǎn)換工具使用方法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-08-08windows中安裝Python3.8.0的實現(xiàn)方法
這篇文章主要介紹了windows中安裝Python3.8.0的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11