pyqt5窗体之间传值

我想设计一个登录窗口, 登录成功后, 在主界面显示登录成功的帐号. 

login.py

import sys
from PyQt5 import QtWidgets
from win.login_win import Ui_login_form
from main import mainWin
from include.data_verify import *


class login_window(QtWidgets.QMainWindow, Ui_login_form):

    def __init__(self):
        super(login_window, self).__init__()
        self.setupUi(self)

        self.Login_OK.clicked.connect(self.loginCheck)

    def loginCheck(self):
        account = self.Login_phone.text()
        password = self.Login_pwd.text()
        if account == "" or password == "":
            self.tongzhi.setText("手机号或密码不能为空!")
        else:
            error_code = loginVerify(account, password)
            if error_code[0] == 1:
                self.tongzhi.setText("登录失败 code = -1")
            elif error_code[0] == 2:
                self.tongzhi.setText("登录失败 code = -2")
            elif error_code[0] == 3:
                self.tongzhi.setText("用户名或密码不正确!")
            elif error_code[0] == 4:
                mainWin.show()
                self.close()
            else:
                self.tongzhi.setText("登录失败 code = -3")


if __name__ == ‘__main__‘:
    app = QtWidgets.QApplication(sys.argv)
    loginWin = login_window()
    mainWin = mainWin()
    loginWin.show()
    sys.exit(app.exec_())

main.py

from PyQt5 import QtWidgets
from win.main_win import Ui_MainWindow
from win.login_win import Ui_login_form


class loginWin(QtWidgets.QMainWindow, Ui_login_form):
    def __init__(self):
        super(loginWin, self).__init__()
        self.setupUi(self)


class mainWin(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(mainWin, self).__init__()
        self.setupUi(self)

        self.comNum1 = QtWidgets.QLabel(当前登录帐号:‘)
        self.statusbar.addPermanentWidget(self.comNum1, stretch=1)

 来源 :站长资讯中心

pyqt5窗体之间传值

上一篇:最新版jmeter与jdk的安装(win10)


下一篇:浅析C#中 ConcurrentDictionary的实现