Problem with 'if' statement in OOP

I’m having a problem trying to close one window while opening the other. What I have works well, if the fields are not filled in, the message pops up, if they are correct the other new window appears and the old one closes.

The problem is that if I fill in the fields and they are incorrect data, the first window closes. and I don’t know how to make a condition to verify that they are incorrect data.

I am doing it in object-oriented programming, so I don’t know how to verify the data entered in one file and in another.

In the main file I have this:

def login(self):
		datos = (self.formUsuarioString.get(), self.formPasswordString.get())
		if self.formUsuarioString.get() == "" or self.formPasswordString.get() == "":
			MessageBox.showinfo("INFORMACION", "Debes rellenar todos los campos.")

and in the other file:

def verificar(self, datos):
		con1 = self.conexion()
		cur = con1.cursor()
		sql = "SELECT * FROM trabajador WHERE nombre=%s AND password=%s"
		if comprobardatosAcceso:
			print ("hay registro")
			for i in comprobardatosAcceso:
				print("Hola: " + i['nombre'] + " con email: " + i['email'])

			self.ventana2 = Tk()
			self.ventana2.title("Hola: " + i['nombre'])


			MessageBox.showinfo("INFORMACION", "No existe ningun usuario asi")

How would be the solution to verify the data entered through object-oriented programming.

any additional information would be appreciated.


Hi, tomassanchezgarcia

Make your verificar function to return true or false depending on the verification result:

Then use it to decide if you should close current window:

if self.conexion1.verificar(datos):

I would also move any logic which doesn’t relate with verification itself to outside of this function. This will make your code cleaner. Learn more about Single-responsibility principle.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.