-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistrar.py
167 lines (136 loc) · 5.78 KB
/
registrar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from tkinter import *
from tkinter import ttk # for the Checkbutton
from tkcalendar import DateEntry
from create_user import CreateUserDict, JSONBuilder
import json
# Create an empty list to store the Entry widgets
entry_widgets = []
def new_alumn():
entry_values = [entry.get() for entry in entry_widgets]
entry_values.append(tipo.alumn) #default
entry_values.append("true") #condicional, verficar.
user = CreateUserDict(*entry_values)
#Store it
JSONBuilder(user)
class tipo:
alumn = "alumn"
admin = "admin"
catdr = "cat"
def iniciar_sesion():
user = usuario_entry.get()
contrasena = contrasena_entry.get()
isUser = False
isPass = False
with open('./users.json', 'r') as f:
data = json.load(f)
for item in data:
if user in item:
isUser = True
if item[user]['password'] == contrasena:
isPass = True
break
# Manejo de errores
if not isUser:
user_existn.pack()
else:
user_existn.pack_forget()
if not isPass:
pass_existn.pack()
else:
pass_existn.pack_forget()
# View fork
if item[user]['tipo'] == tipo.alumn:
vista_alumno()
elif item[user]['tipo'] == tipo.catdr:
vista_catedra()
elif item[user]['tipo'] == tipo.admin:
vista_admin()
def vista_alumno():
global entry_widgets
global titulo_alumno, sign_out_button
entry_widgets = [] # Clear the previous entries if any
# Destroy previous widgets
titulo.destroy()
usuario_label.destroy()
usuario_entry.destroy()
contrasena_label.destroy()
contrasena_entry.destroy()
iniciar_sesion_button.destroy()
registrar_button.destroy()
# New Title
titulo_alumno = Label(ventana, text="Alumno", font=("Helvetica", 40, "bold"))
titulo_alumno.place(relx=0.5, rely=0.1, anchor='center')
# Cerrar Sesión
sign_out_button = Button(ventana, text="Cerrar Sesión", font=("Helvetica", 16), command=build_main_view)
sign_out_button.place(relx=0.5, rely=0.9, anchor='center')
def abrir_registro():
global entry_widgets # Declare as global to modify it
entry_widgets = [] # Clear the previous entries if any
# Destroy previous widgets
titulo.destroy()
usuario_label.destroy()
usuario_entry.destroy()
contrasena_label.destroy()
contrasena_entry.destroy()
iniciar_sesion_button.destroy()
registrar_button.destroy()
# New Title
titulo_registro = Label(ventana, text="Página de Registro", font=("Helvetica", 40, "bold"))
titulo_registro.place(relx=0.5, rely=0.1, anchor='center')
# New Form Fields
campos = ["Usuario","Nombre", "Apellido", "Fecha de Nacimiento", "Teléfono", "DPI", "Email", "Contraseña"]
for index, campo in enumerate(campos):
Label(ventana, text=campo, font=("Helvetica", 16)).place(relx=0.35, rely=0.2 + index*0.1, anchor='center')
if campo == "Fecha de Nacimiento":
entry = DateEntry(ventana, width=16, background="magenta3", foreground="white", bd=2)
else:
entry = Entry(ventana, font=("Helvetica", 16))
entry.place(relx=0.65, rely=0.2 + index*0.1, anchor='center')
entry_widgets.append(entry) # Append to the list
# Register button for the new form
registro_button = Button(ventana, text="Registrar", font=("Helvetica", 16), command=new_alumn)
registro_button.place(relx=0.5, rely=0.95, anchor='center')
def main_view():
global titulo, usuario_label, usuario_entry, contrasena_label, contrasena_entry
global iniciar_sesion_button, registrar_button, user_existn, pass_existn
# Título
font_style = ("Helvetica", 12)
titulo = Label(ventana, text="Facultad de Ingeniería", font=("Helvetica", 40, "bold"))
titulo.place(relx=0.5, rely=0.2, anchor='center')
# Usuario
usuario_label = Label(ventana, text="Usuario:", font=("Helvetica", 16))
usuario_label.place(relx=0.5, rely=0.4, anchor='center')
usuario_entry = Entry(ventana, font=("Helvetica", 16))
usuario_entry.place(relx=0.5, rely=0.45, anchor='center')
# Contraseña
contrasena_label = Label(ventana, text="Contraseña:", font=("Helvetica", 16))
contrasena_label.place(relx=0.5, rely=0.55, anchor='center')
contrasena_entry = Entry(ventana, show="*", font=("Helvetica", 16))
contrasena_entry.place(relx=0.5, rely=0.6, anchor='center')
# Botones
iniciar_sesion_button = Button(ventana, text="Iniciar Sesión", font=("Helvetica", 16), command=iniciar_sesion)
iniciar_sesion_button.place(relx=0.5, rely=0.7, anchor='center')
registrar_button = Button(ventana, text="Registrarse", font=("Helvetica", 16), command=abrir_registro)
registrar_button.place(relx=0.5, rely=0.8, anchor='center')
user_existn = Label(ventana, text="Usuario no registrado", font=font_style, fg="red")
user_existn.place(relx=0.5, rely=0.75, anchor='center')
pass_existn = Label(ventana, text="Contraseña incorrecta", font=font_style, fg="red")
pass_existn.place(relx=0.5, rely=0.8, anchor='center')
# Initially, hide them
user_existn.place_forget()
pass_existn.place_forget()
def build_main_view():
titulo_alumno.destroy()
sign_out_button.destroy()
# Destroy current widgets if any (be careful with this approach)
for widget in ventana.winfo_children():
widget.pack_forget()
# Rebuild main view (This should replicate your main view widgets)
main_view() # Define this function to contain your main view code
# Configuración de la ventana principal
ventana = Tk()
ventana.title("Facultad de Ingenieria")
ventana.attributes('-fullscreen', True)
main_view()
# Ejecutar la aplicación
ventana.mainloop()