[pyqt5][python][原创]pyqt5登陆界面跳转并关闭子窗口全部退出

Posted FL1623863129

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[pyqt5][python][原创]pyqt5登陆界面跳转并关闭子窗口全部退出相关的知识,希望对你有一定的参考价值。

登陆界面:(designer随便画个ui文件然后用pyuic转化)

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(260, 70, 261, 31))
        self.textEdit.setObjectName("textEdit")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(210, 260, 331, 111))
        self.pushButton.setObjectName("pushButton")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(200, 80, 55, 18))
        self.label.setObjectName("label")
        self.textEdit_2 = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit_2.setGeometry(QtCore.QRect(260, 110, 261, 31))
        self.textEdit_2.setObjectName("textEdit_2")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(200, 120, 55, 18))
        self.label_2.setObjectName("label_2")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "login"))
        self.label.setText(_translate("MainWindow", "user"))
        self.label_2.setText(_translate("MainWindow", "password"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

主界面:(designer随便画个ui文件然后用pyuic转化)

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(220, 190, 281, 111))
        self.pushButton.setObjectName("pushButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "PushButton"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

登陆界面研究.py

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
# 导入login_window.py、my_main_window.py里面全部内容
import login_window
import main_window


# 创建main_window类继承my_main_window.py里面全部内容
class main_win(main_window.Ui_MainWindow, QMainWindow):
    def __init__(self):
        super(main_win, self).__init__()
        self.setupUi(self)

    def closeEvent(self, event):
        print('close')
        sys.exit(0)


class login_window(login_window.Ui_MainWindow, QMainWindow):
    def __init__(self):
        super(login_window, self).__init__()
        self.setupUi(self)
        self.main_window = None

    def show_child_window(self):
        self.main_window.show()
        self.setVisible(False)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 为main_window类和login_window类创建对象
    main_win = main_win()
    login_window = login_window()
    login_window.main_window = main_win
    # 显示登陆窗口
    login_window.show()
    # 将显示main_window与单击登录页面按钮绑定
    login_window.pushButton.clicked.connect(login_window.show_child_window)
    # 关闭程序,释放资源
    sys.exit(app.exec_())

以上是关于[pyqt5][python][原创]pyqt5登陆界面跳转并关闭子窗口全部退出的主要内容,如果未能解决你的问题,请参考以下文章

Python IDE PyCharm+PyQt5环境配置

基于pyQt5开发的股价显示器(原创)

[vscode][原创]pyqt5配置后报错:qt.qpa.plugin: Could not find the Qt platform plugin “windows“ in ““

PyQt5 安装教程

python pyqt5 自定义信号和槽

Python,pyqt5