class LoginWindow(QWidget): def __init__(self): QMainWindow.__init__(self) ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( "myappid") # 系统图标 self.setWindowIcon(QIcon('.\images\Iron.png')) self.main_ui = Ui_login() self.main_ui.setupUi(self) def paintEvent(self, event): # set background_img painter = QPainter(self) painter.drawRect(self.rect()) pixmap = QPixmap(login_imgpath) # 换成自己的图片的相对路径 painter.drawPixmap(self.rect(), pixmap)
class LoginWindow(QDialog): def __init__(self): super(LoginWindow, self).__init__() self.li = Ui_login() self.li.setupUi(self) self.li.ok.clicked.connect(self.Login) #function for login called when pressed 'ok' on login window def Login(self): key = self.li.password.text() user = self.li.username.text() #print(key) if key == 'eid' and user == 'shreya': print('Logged in') self.accept() print('closed') elif key == 'eid' and user != 'shreya': self.li.username.setText('Wrong Username') elif key != 'eid' and user == 'shreya': self.li.username.setText('Wrong Password') else: self.li.username.setText('Wrong User & Password')
class Login(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.msg = QMessageBox() self.connect_Account() self.login = Ui_login() self.login.setupUi(self) self.vet = Veterinary() self.adm = Admin() self.ref = Refuge() self.connections = [] self.login.loginPushButton.clicked.connect(self.compare_Account) self.tcpServer = QTcpServer() self.tcpServer.listen(QHostAddress("0.0.0.0"),9999) self.tcpServer.newConnection.connect(self.addConnections) def addConnections(self): clientConnection = self.tcpServer.nextPendingConnection() clientConnection.nextBlockSize = 0 self.connections.append(clientConnection) self.connect(clientConnection, SIGNAL("readyRead()"), self.receiveMessage) def receiveMessage(self): for s in self.connections: if s.bytesAvailable() > 0: stream = QDataStream(s) stream.setVersion(QDataStream.Qt_4_2) if s.nextBlockSize == 0: if s.bytesAvailable() < 4: return s.nextBlockSize = stream.readUInt32() if s.bytesAvailable() < s.nextBlockSize: return textFromClient = stream.readQString() s.nextBlockSize = 0 self.sendMessage(textFromClient, s.socketDescriptor()) s.nextBlockSize = 0 def sendMessage(self, text, socketId): for s in self.connections: if s.socketDescriptor() == socketId: message = "Tu> {}".format(text) else: message = "{}> {}".format(socketId, text) reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(message) stream.device().seek(0) stream.writeUInt32(reply.size() - 4) s.write(reply) def connect_Account(self): db = QSqlDatabase.addDatabase('QSQLITE') db.setDatabaseName('database.db') if db.open() == False: self.msg.information(self,"informativo","No se conecto la base de datos") def compare_Account(self): try: query = "SELECT * FROM admin" sql = QSqlQuery() sql.prepare(query) state = sql.exec_() sig = False while sql.next(): if self.login.userLineEdit.text() == sql.value(5) and self.login.passLineEdit.text() == sql.value(9) and self.login.loginComboBox.currentText() == 'Veterinaria': sig = True self.vet.show() elif self.login.userLineEdit.text() == sql.value(5) and self.login.passLineEdit.text() == sql.value(9) and self.login.loginComboBox.currentText() == 'Adm': self.adm.show() sig = True elif self.login.userLineEdit.text() == sql.value(5) and self.login.passLineEdit.text() == sql.value(9) and self.login.loginComboBox.currentText() == 'Refugio': self.ref.show() sig = True if sig == False: self.msg.information(self,"informativo","usuario o contraseña erronea") self.login.userLineEdit.setFocus() except: self.msg.information(self,"informativo","Error en la consulta") finally: self.login.userLineEdit.clear() self.login.passLineEdit.clear()