这是主文件,当我单击注册按钮QCoreApplication :: exec时:事件循环已在运行

时间:2018-11-02 07:48:49

标签: python pyqt5

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui
import sqlite3
from welcome import Ui_Dialog
from sign1 import Ui_Signup1
import re
from PyQt5.QtWidgets import QApplication, QMainWindow


class Ui_Dialog(object):   
    def showMessageBox(self,title,message):
        msgBox = QtWidgets.QMessageBox()
        msgBox.setIcon(QtWidgets.QMessageBox.Warning)    
        msgBox.setWindowTitle(title)
        msgBox.setText(message)
        msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
        msgBox.exec_()

    def signUpShow(self):
        self.signUpWindow = QtWidgets.QMainWindow()
        self.ui = Ui_Signup1()
        self.ui.setupUi(self.signUpWindow)
        self.signUpWindow.show()

    def loginCheck(self):
        username = self.uname_lineEdit.text()
        password = self.pass_lineEdit.text()
        self.showMessageBox('Warning!','invalid Username and Password')


        conn = sqlite3.connect("Logi.db")
        result = conn.execute("SELECT * FROM NAT WHERE USERNAME = ?  AND PASSWORD = ?",(username,password))
        conn.commit()

        if(len(result.fetchall()) > 0):
            # print("user found !")
            self.showMessageBox('Warning!','InValid Username and Password')            
        else:
            print("user not found !") 
            self.showMessageBox('Warning!','invalid Username and Password')    
        conn.close()

    def signupCheck(self):
        print("SignUp Button Clicked")
        self.signUpShow()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        # MainWindow.resize(468, 600)
        MainWindow.setFixedWidth(500)
        MainWindow.setFixedHeight(500)
        # MainWindow.setStyleSheet(open('shtylesheet.css').read())
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("C:/Users/dhaval.panchal/Desktop/pyqt/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.centralwidget.setStyleSheet("background-color:#74992e")
        self.u_name_label = QtWidgets.QLabel(self.centralwidget)
        self.u_name_label.setGeometry(QtCore.QRect(170, 180, 81, 20))
        self.u_name_label.setObjectName("u_name_label")
        self.pass_label = QtWidgets.QLabel(self.centralwidget)
        self.pass_label.setGeometry(QtCore.QRect(170, 230, 81, 20))
        self.pass_label.setObjectName("pass_label")
        self.uname_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.uname_lineEdit.setGeometry(QtCore.QRect(260, 180, 113, 20))
        self.uname_lineEdit.setObjectName("uname_lineEdit")
        self.pass_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.pass_lineEdit.setGeometry(QtCore.QRect(260, 230, 113, 20))
        self.pass_lineEdit.setObjectName("pass_lineEdit")
        self.pass_lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.login_btn = QtWidgets.QPushButton(self.centralwidget)
        self.login_btn.setGeometry(QtCore.QRect(230, 300, 75, 23))
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        font.setStrikeOut(False)
        font.setKerning(False)
        self.login_btn.setFont(font)
        self.login_btn.setObjectName("login_btn")
        self.login_btn.setStyleSheet("background-color:brown; color:teal;font-size:15px;border:1px solid brown")
        self.signup_btn = QtWidgets.QPushButton(self.centralwidget)
        self.signup_btn.setGeometry(QtCore.QRect(320, 300, 75, 23))
        self.signup_btn.setStyleSheet("background-color:brown; color:teal;font-size:15px;border:1px solid brown")
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        font.setStrikeOut(False)
        font.setKerning(False)
        self.signup_btn.setFont(font)
        self.signup_btn.setObjectName("signup_btn")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(240, 90, 131, 41))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

        self.login_btn.clicked.connect(self.loginCheck)
        self.signup_btn.clicked.connect(self.signupCheck)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Login Form:)"))
        self.u_name_label.setText(_translate("MainWindow", "USERNAME"))
        self.pass_label.setText(_translate("MainWindow", "PASSWORD"))
        self.login_btn.setText(_translate("MainWindow", "LOGIN"))
        self.signup_btn.setText(_translate("MainWindow", "SIGN UP"))
        self.label.setText(_translate("MainWindow", "LOGIN FORM"))

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

0 个答案:

没有答案