open a QMessageBox inside a QMainWindows already open

0

Searching in a network to manipulate windows, from a main window, I will be able to do it, what I do not find yet, is already running the program, in the login to put both user and password as admin, I should leave a QMessageBox , with any message ("welcome"). I run everything when instead of putting the QMessageBox, I call another window PD: the other function calls work for me, I have tried them without the QMessageBox and it runs normally, I have Python 3.7.1

import sys from PyQt5 import *

class login (QMainWindow):

def __init__(self):
    super(login, self).__init__()    
    loadUi('login.ui', self)
    rutaDeImagen = "C:/Users/AlvaroMartin/Desktop/rostro.jpg"
    self.loginTLfoto.setPixmap(QtGui.QPixmap(rutaDeImagen))
    self.loginJBIngresar.clicked.connect(self.buttonClicked)


def buttonClicked(self, e):
    if(self.loginTFusuario.text() == "admin" and self.loginTFcontra.text() == "admin"):

        rutaDeImagenA = "C:/Users/AlvaroMartin/Desktop/admin.jpg"
        self.loginTLfoto.setPixmap(QtGui.QPixmap(rutaDeImagenA))

        #self.loginJBIngresar.clicked.connect(self.loginCheck)
        self.loginCheck()
        self.cambiosEnLogin()

        #self.showMessageBox('Warning','Invalid Username And Password')

        #self.abrirVentanaAdmin()

        # se agregara la opcion de que cambie la foto del admin 
    else:
        self.cambiosEnLogin()
        self.abrirVentanaUsuario()
        self.loginJBIngresar.clicked.connect(self.abrirVentanaUsuario)


def loginCheck(self):
    print("UNA LINEA ANTES DEÑ MSSBOX ")
    self.showMessageBox('Warning','Invalid Username And Password')
    print("DESPUES DEL MSSBOX")

def showMessageBox(self,title,message):
    msgBox = QtGui.QMessageBox()
    msgBox.setIcon(QtGui.QMessageBox.Warning)
    msgBox.setWindowTitle(title)
    msgBox.setText(message)
    msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
    msgBox.exec_()
    
asked by Alvaro Martin Begazo Carhuayo 26.10.2018 в 01:51
source

1 answer

0

If someone serves, I could do it, I do not know if it is because it overloaded with the import of all the modules of (from PyQt5 import *), it is what I believe, but it could also be because I moved other things, I leave the code with which if everything works normal. Greetings

import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox from PyQt5 import QtGui from PyQt5.uic import loadUi

class login (QMainWindow):

def __init__(self):
    super(login, self).__init__()    
    loadUi('login.ui', self)
    rutaDeImagen = "C:/Users/AlvaroMartin/Desktop/rostro.jpg"
    self.loginTLfoto.setPixmap(QtGui.QPixmap(rutaDeImagen))
    self.loginJBIngresar.clicked.connect(self.buttonClicked)

def buttonClicked(self, e):
    if((self.loginTFusuario.text() == "" and self.loginTFcontra.text() == "") or (self.loginTFusuario.text() == "" and self.loginTFcontra.text() != "") or (self.loginTFusuario.text() != "" and self.loginTFcontra.text() == "") ):
        QMessageBox.information(self, "ERROR", "Complete ambos campos, o Ingrese correctamente sus datos", QMessageBox.Ok)
        self.cambiosEnLogin()
    else:
        if(self.loginTFusuario.text() == "admin" and self.loginTFcontra.text() == "admin"):

            rutaDeImagenA = "C:/Users/AlvaroMartin/Desktop/admin.jpg"
            self.loginTLfoto.setPixmap(QtGui.QPixmap(rutaDeImagenA))

            QMessageBox.information(self, "Correcto", "Bienvenido Administrador", QMessageBox.Ok)

            self.cambiosEnLogin()
            self.abrirVentanaAdmin()

        else:
            QMessageBox.information(self, "Correcto", "Bienvenido Usuario", QMessageBox.Ok)
            self.cambiosEnLogin()
            self.abrirVentanaUsuario()

def cambiosEnLogin(self):
    self.loginTFusuario.setText("")
    self.loginTFcontra.setText("")
    rutaDeImagen = "C:/Users/AlvaroMartin/Desktop/rostro.jpg"
    self.loginTLfoto.setPixmap(QtGui.QPixmap(rutaDeImagen))

def crearMensaje(self):
    a = QMessageBox()
    a.information(self,"Advertencia","Llenelos")
    a.show()
    
answered by 26.10.2018 в 02:22