• 使用PyQt5完成登陆进入主窗体


    login.py

    import sys
    from PyQt5 import QtWidgets, QtCore
    from PyQt5.QtWidgets import QMessageBox
    import ui_login
    import main

    class frmLogin(QtWidgets.QWidget, ui_login.Ui_frmLogin):
    def __init__(self):
    super(frmLogin, self).__init__()
    self.setupUi(self)
    self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) #禁止最大化按钮

    # 创建槽函数 槽函数直接使用元件的名称:on_元件名称_信号名称(槽装饰器, 区分参数)
    @QtCore.pyqtSlot() #@QtCore.pyqtSlot(bool)
    def on_btnLogin_clicked(self): #自动对应click
    user = self.edtUser.text().strip()
    passwd = self.edtPasswd.text().strip()
    if user == "":
    QMessageBox.warning(self,"警告","用户号不能为空,请输入!")
    return
    if passwd == "":
    QMessageBox.warning(self,"警告","密码不能为空,请输入!")
    return
    if len(user) != 7:
    QMessageBox.warning(self,"警告","用户号长度必须为7位!")
    return
    if len(passwd) < 6:
    QMessageBox.warning(self,"警告","密码长度不能小于6位!")
    return
    if passwd != '123456':
    QMessageBox.warning(self,"警告","密码不符无法登陆!")
    return

    frmMain.show() #打开新窗口
    self.close() #关闭本窗口

    if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    frmLogin = frmLogin()
    frmMain = main.frmMain()
    frmLogin.show()
    sys.exit(app.exec_())
    --------------------------------------------------------------------------
    main.py
    from PyQt5 import QtWidgets
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtCore import Qt
    import ui_main

    class frmMain(QtWidgets.QMainWindow, ui_main.Ui_frmMain):
    def __init__(self):
    super(frmMain, self).__init__()
    self.setupUi(self)

    def closeEvent(self, event):
    reply = QMessageBox.question(self,'提示信息',"您是否退出程序?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
    if reply == QMessageBox.Yes:
    event.accept()
    else:
    event.ignore()

    def keyPressEvent(self, e):
    if e.key() == Qt.Key_Escape:
    self.close()
  • 相关阅读:
    关于Lucas定理、多项式Exp的一些思考
    Binet-Cauchy定理的证明
    CSP2019 树上的数 题解
    Graphviz学习
    Luogu P2221 [HAOI2012]高速公路题解
    CSP2019 树的重心 题解
    CSP2019 Emiya 家今天的饭 题解
    UVA10559 方块消除 Blocks 题解
    关于二次项系数为1的二元一次不定方程解法的探究
    关于对STL容器重载运算符的问题
  • 原文地址:https://www.cnblogs.com/zsfishman/p/11483005.html
Copyright © 2020-2023  润新知