如何使用PyQt在窗口中切换布局?(没有关闭打开窗口)

如何使用PyQt在窗口中切换布局?(没有关闭打开窗口),第1张

如何使用PyQt在窗口切换布局?(没有关闭/打开窗口)
from PyQt4 import QtCore, QtGuiclass MainWindow(QtGui.QMainWindow):    def __init__(self, parent=None):        super(MainWindow, self).__init__(parent)        self.central_widget = QtGui.QStackedWidget()        self.setCentralWidget(self.central_widget)        login_widget = LoginWidget(self)        login_widget.button.clicked.connect(self.login)        self.central_widget.addWidget(login_widget)    def login(self):        logged_in_widget = LoggedWidget(self)        self.central_widget.addWidget(logged_in_widget)        self.central_widget.setCurrentWidget(logged_in_widget)class LoginWidget(QtGui.QWidget):    def __init__(self, parent=None):        super(LoginWidget, self).__init__(parent)        layout = QtGui.QHBoxLayout()        self.button = QtGui.QPushButton('Login')        layout.addWidget(self.button)        self.setLayout(layout)        # you might want to do self.button.click.connect(self.parent().login) hereclass LoggedWidget(QtGui.QWidget):    def __init__(self, parent=None):        super(LoggedWidget, self).__init__(parent)        layout = QtGui.QHBoxLayout()        self.label = QtGui.QLabel('logged in!')        layout.addWidget(self.label)        self.setLayout(layout)if __name__ == '__main__':    app = QtGui.QApplication([])    window = MainWindow()    window.show()    app.exec_()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5617871.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存