您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“python怎么通過(guò)PyQt5實(shí)現(xiàn)登錄界面”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“python怎么通過(guò)PyQt5實(shí)現(xiàn)登錄界面”吧!
1. pyQt5簡(jiǎn)單使用
安裝
界面化操作
2.開(kāi)始實(shí)現(xiàn)登錄界面
pip install PyQt5 pip3.5 install pyqt5-tools
1.在win+R中輸入designer并敲回車(chē),即可啟動(dòng)Designer。一般選擇“Main Window”點(diǎn)擊“Create”即可創(chuàng)建。
若在win+R中輸入designer并敲回車(chē)后無(wú)反應(yīng),可以直接搜designer.exe直接啟動(dòng)
2.創(chuàng)建后,可以方便快捷的用Qt Designer畫(huà)出對(duì)應(yīng)框體,如通過(guò)Combo Box添加下拉選擇的控件;通過(guò)Push Button添加按鈕;通過(guò)List Widget添加列表框;通過(guò)Table Widget添加數(shù)據(jù)表格框,table中設(shè)置列數(shù)(右鍵-Edit Items-Colums),調(diào)整框體位置和文字大小,背景顏色以及windowTitle來(lái)優(yōu)化界面顯示,使用快捷鍵Ctrl+R預(yù)覽當(dāng)前編寫(xiě)的GUI顯示如下:
3.點(diǎn)擊保存,生成*.ui的文件,本例中為test.ui,保存在D:\py\deploy文件夾下
import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * #創(chuàng)建主窗口 class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('主界面') self.showMaximized() #對(duì)話框 class logindialog(QDialog): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('登錄界面') self.resize(200, 200) self.setFixedSize(self.width(), self.height()) self.setWindowFlags(Qt.WindowCloseButtonHint) ###### 設(shè)置界面控件 self.frame = QFrame(self) self.verticalLayout = QVBoxLayout(self.frame) self.lineEdit_account = QLineEdit() self.lineEdit_account.setPlaceholderText("請(qǐng)輸入賬號(hào)") self.verticalLayout.addWidget(self.lineEdit_account) self.lineEdit_password = QLineEdit() self.lineEdit_password.setPlaceholderText("請(qǐng)輸入密碼") self.verticalLayout.addWidget(self.lineEdit_password) self.pushButton_enter = QPushButton() self.pushButton_enter.setText("確定") self.verticalLayout.addWidget(self.pushButton_enter) self.pushButton_quit = QPushButton() self.pushButton_quit.setText("取消") self.verticalLayout.addWidget(self.pushButton_quit) ###### 綁定按鈕事件 self.pushButton_enter.clicked.connect(self.on_pushButton_enter_clicked) self.pushButton_quit.clicked.connect(QCoreApplication.instance().quit) def on_pushButton_enter_clicked(self): # 賬號(hào)判斷 if self.lineEdit_account.text() == "": return # 密碼判斷 if self.lineEdit_password.text() == "": return # 通過(guò)驗(yàn)證,關(guān)閉對(duì)話框并返回1 self.accept() #程序入門(mén) if __name__ == "__main__": app = QApplication(sys.argv) dialog = logindialog() if dialog.exec_()==QDialog.Accepted: the_window = MainWindow() the_window.show() sys.exit(app.exec_())
到此,相信大家對(duì)“python怎么通過(guò)PyQt5實(shí)現(xiàn)登錄界面”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。