from tkinter import *
from tkinter import ttk
import tkinter as tk
import pymysql
from conexion import *
from tkinter import messagebox
from PIL import Image, ImageTk
from test2 import Menus
class Login:
def __init__(self, app):
self.app = app
self.t_Email = "Email:"
self.label_email = tk.Label(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.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(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(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(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.fetchall()
#messagebox.showwarning("Advertencia", self.verificar_login)
# Conectarse a la base de datos utilizando la función importada
self.connection2 = connect_to_database()
self.cursor2 = self.connection2.cursor()
# Ejemplo: Ejecutar una consulta para obtener datos
self.cursor2.execute("SELECT nombre,password FROM usuarios")
self.data2 = self.cursor2.fetchall()
#messagebox.showwarning("Advertencia", self.data2)
# Cerrar el cursor y la conexión
for self.fila in self.data2:
self.v_email = self.fila[0]
self.v_password = self.fila[1]
self.cursor2.close()
self.connection2.close()
if self.entry_email.get() == "" or self.entry_password.get() == "":
self.dialogo = tk.Toplevel()
self.dialogo.title("Diálogo Personalizado")
self.dialogo.geometry("300x50")
self.dialogo.resizable(0,0)
self.wtotal2 = self.dialogo.winfo_screenwidth()
self.htotal2 = self.dialogo.winfo_screenheight()
self.wventana2 = 300
self.hventana2 = 50
self.pwidth2 = round(self.wtotal2/2-self.wventana2/2)
self.pheight2 = round(self.htotal2/2-self.hventana2/2)
self.dialogo.geometry(str(self.wventana2)+"x"+str(self.hventana2)+"+"+str(self.pwidth2)+"+"+str(self.pheight2))
self.etiqueta = tk.Label(self.dialogo, text="Este es un cuadro de diálogo personalizado.", padx=10, pady=10)
self.etiqueta.pack()
elif self.entry_email.get() == self.v_email and self.entry_password.get() == self.v_password:
#messagebox.showwarning("Advertencia", "PERFECTO COINCIDE")
self.ventana_menu = Menus(self)
else:
self.root.destroy()
messagebox.showwarning("Advertencia", "Los datos introducidos son incorrectos.")