Hello, I have a problem with importing a function, so far everything worked fine for me until I did the validate function and called it from the button, why am I getting this error?
Main.py
class AplicacionInventario:
def __init__(self):
self.root = Tk()
self.root.title("StockMaster")
self.root.geometry("400x500")
self.root.resizable(0,0)
self.wtotal = self.root.winfo_screenwidth()
self.htotal = self.root.winfo_screenheight()
self.wventana = 400
self.hventana = 500
self.pwidth = round(self.wtotal/2-self.wventana/2)
self.pheight = round(self.htotal/2-self.hventana/2)
self.root.geometry(str(self.wventana)+"x"+str(self.hventana)+"+"+str(self.pwidth)+"+"+str(self.pheight))
self.imagen = Image.open("src/logo.png")
self.imagen = self.imagen.resize((350, 100))
self.imagen = ImageTk.PhotoImage(self.imagen)
self.label_imagen = tk.Label(self.root, image=self.imagen)
self.label_imagen.pack(pady=20)
self.prueba = login(self)
self.root.mainloop()
AplicacionInventario()
loggin.py
def login(self):
self.t_Email = "Email:"
self.label_email = tk.Label(self.root, text=self.t_Email)
self.label_email.pack(pady=5, padx=20)
self.label_email.place(x=150, y=150, width=100, height=20)
self.entry_email = tk.Entry(self.root)
self.entry_email.pack(pady=5)
self.entry_email.place(x=75, y=170, width=250, height=50)
self.t_Password = "Contraseña:"
self.label_password = tk.Label(self.root, text=self.t_Password)
self.label_password.pack(pady=5, padx=20)
self.label_password.place(x=150, y=220, width=100, height=20)
self.entry_password = tk.Entry(self.root, show="*")
self.entry_password.pack(pady=5)
self.entry_password.place(x=75, y=240, width=250, height=50)
self.login_email = self.entry_email.get()
self.login_password = self.entry_password.get()
self.boton_login = tk.Button(self.root, text="Iniciar Sesión", command=self.validar)
self.boton_login.pack(pady=5)
self.boton_login.place(x=125, y=300, width=150, height=50)
def validar(self):
self.conexion_login = connect_to_database()
self.cursor_conexion_login = self.conexion_login.cursor()
self.cursor_conexion_login.execute("SELECT email, password FROM usuarios WHERE email=%s AND password=%s", (self.login_email, self.login_password))
self.verificar_login = self.cursor_conexion_login.fetchone()
ERROR:
Traceback (most recent call last):
File "/Users/tomassanchezgarcia/Desktop/python-test/main.py", line 64, in <module>
AplicacionInventario()
File "/Users/tomassanchezgarcia/Desktop/python-test/main.py", line 38, in __init__
self.prueba = login(self)
^^^^^^^^^^^
File "/Users/tomassanchezgarcia/Desktop/python-test/iniciar_sesion.py", line 31, in login
self.boton_login = tk.Button(self.root, text="Iniciar Sesión", command=self.validar)
^^^^^^^^^^^^
AttributeError: 'AplicacionInventario' object has no attribute 'validar'
What I have tried:
Hello, I have a problem with importing a function, so far everything worked fine for me until I did the validate function and called it from the button, why am I getting this error?
how can I solve that?
Any additional information would be appreciated.