pyqt5界面切換


#主要的思路就是創建兩個frame(如果有兩個以上同理)使用setVisible()函數顯示或者隱藏frame 參數是bool值
import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * 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) self.frame = QFrame(self) self.verticalLayout = QVBoxLayout(self.frame) self.lineEdit_account = QLineEdit() self.lineEdit_account.setPlaceholderText("請輸入賬號") self.verticalLayout.addWidget(self.lineEdit_account) self.lineEdit_password = QLineEdit() self.lineEdit_password.setPlaceholderText("請輸入密碼") self.verticalLayout.addWidget(self.lineEdit_password) self.pushButton_enter = QPushButton() self.pushButton_enter.setText("進入下一個界面") self.verticalLayout.addWidget(self.pushButton_enter) self.frame1 = QFrame(self) self.verticalLayout = QVBoxLayout(self.frame1) self.pushButton_quit = QPushButton() self.pushButton_quit.setText("回到主頁面") self.verticalLayout.addWidget(self.pushButton_quit) self.frame1.setVisible(False) self.pushButton_enter.clicked.connect(self.on_pushButton_enter_clicked) self.pushButton_quit.clicked.connect(self.on_pushButton_enter_clicked_1) def on_pushButton_enter_clicked(self): self.frame1.setVisible(True) self.frame.setVisible(False) def on_pushButton_enter_clicked_1(self): self.frame1.setVisible(False) self.frame.setVisible(True) if __name__ == "__main__": app = QApplication(sys.argv) dialog = logindialog() if dialog.exec_() == QDialog.Accepted: sys.exit(app.exec_())

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM