Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good,
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:


Python
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.")
		else:
			self.ventana1.destroy()
			self.conexion1.verificar(datos)


and in the other file:

Python
def verificar(self, datos):
		con1 = self.conexion()
		cur = con1.cursor()
		sql = "SELECT * FROM trabajador WHERE nombre=%s AND password=%s"
		cur.execute(sql,datos)
		comprobardatosAcceso=cur.fetchall()
		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'])
			self.ventana2.geometry("400x400")

			self.ventana2.mainloop()

		else:
			print("error")
			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.

Greetings!


What I have tried:

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

any additional information would be appreciated.

Greetings!
Posted
Comments
Richard MacCutchan 23-Jan-22 8:07am    
The login page should be the one to check the inputs, and to get the information from the database. In the code you have above, you open the second window before you know that the entered data is correct.
Tomas Sanchez Garcia 23-Jan-22 8:17am    
I get it,
But how do I use the database connection of the other file?

Or do I have to create a new one?

def login(self):
con1 = self.conexion1
cur = con1.cursor()
sql = "SELECT * FROM trabajador WHERE nombre=%s AND password=%s"
cur.execute(sql,datos)
comprobardatosAcceso=cur.fetchall()
datos = (self.formUsuarioString.get(), self.formPasswordString.get())
if self.formUsuarioString.get() == "" or self.formPasswordString.get() == "":
MessageBox.showinfo("INFORMACION", "Debes rellenar todos los campos.")
else:
self.ventana1.destroy()
self.conexion1.verificar(datos)

that gives me this error:

self.cur = self.con1.cursor()
AttributeError: 'conexiones' object has no attribute 'cursor'
Richard MacCutchan 23-Jan-22 9:28am    
You need to change the order of your actions. Think about what you are trying to do:
1. Check the input strings to ensure the user has entered some text for the name and password.
1.1 if either value is a null or an empty string then post a message and take some error action.
2. If both values contain some text then try to get the record from the database.
2.1 If the login details are not found then report the error.
3. If the login is successful continue to the next part of the application.

Note, you should code and test this part in isolation. There is no point in trying to run the next part until you have this working correctly for all conditions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900