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_())

  

转载于:https://www.cnblogs.com/pythonClub/p/10307155.html

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值