-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreens.py
375 lines (328 loc) · 11.4 KB
/
screens.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import tkinter as tk
from tkinter import messagebox
from constants import style
from database import saldo, username, password
#Crear la ventana de bienvenida
class login(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
self.configure(background=style.home_backg)
self.controller = controller
self.init_widgets_login()
def check_login(self):
user_ingresado = str(self.entry_user.get())
password_ingresado = str(self.entry_password.get())
# Validar credenciales
if user_ingresado == username and password_ingresado == password:
self.controller.show_frame(home)
elif user_ingresado == username and password_ingresado != password:
messagebox.showinfo("Error", "La contraseña ingresada no es correcta.")
elif user_ingresado != username and password_ingresado == password:
messagebox.showinfo("Error", "El usuario ingresado no es correcto.")
else:
messagebox.showinfo("Error", "La contraseña/usuario ingresado no es correcto.")
def init_widgets_login(self):
# Etiqueta de bienvenida
tk.Label(
self,
text="Bienvenido a la Banca Móvil de Station Square",
justify=tk.CENTER,
**style.text_saldo
).pack(
side=tk.TOP,
fill=tk.X,
padx=22,
pady=11,
)
# Etiqueta y entrada de usuario
tk.Label(
self,
text="Usuario:",
justify=tk.LEFT,
**style.text_saldo
).pack(
side=tk.TOP,
anchor=tk.W,
padx=22,
pady=5,
)
self.entry_user = tk.Entry(self, font=('Arial', 15), width=5)
self.entry_user.pack(
side=tk.TOP,
fill=tk.X,
padx=22,
pady=5,
)
# Etiqueta y entrada de contraseña
tk.Label(
self,
text="Contraseña:",
justify=tk.LEFT,
**style.text_saldo
).pack(
side=tk.TOP,
anchor=tk.W,
padx=22,
pady=5,
)
self.entry_password = tk.Entry(self, font=('Arial', 15), show="*")
self.entry_password.pack(
side=tk.TOP,
fill=tk.X,
padx=22,
pady=5,
)
# Crear un Frame para el botón y colocarlo al fondo
button_frame = tk.Frame(self, bg=style.home_backg)
button_frame.pack(side=tk.BOTTOM, fill=tk.X, pady=15)
tk.Button(
button_frame,
width=30,
text="Login",
command=lambda: self.check_login(),
**style.text_style
).pack(
side=tk.BOTTOM,
padx=15,
pady=5,
)
#Crear la pantalla de menú principal
class home(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
self.configure(background = style.home_backg)
self.controller = controller
self.init_widgets_home()
#Definir el método para depositar
def jump_to_deposit(self):
self.controller.show_frame(deposit)
#Definir el método para retirar
def jump_to_withdraw(self):
self.controller.show_frame(withdraw)
#Colocar los widgets en el frame del menú principal
def init_widgets_home(self):
self.label_saldo=tk.Label(
self,
text=f"Su Saldo :{saldo:.2f}",
justify=tk.CENTER,
**style.text_saldo
)
self.label_saldo.pack(
side=tk.TOP,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
#Widget para ir al menú de Retiro
tk.Button(
self,
width=30,
text="Retirar",
command=lambda: self.jump_to_withdraw(),
justify=tk.CENTER,
**style.text_style
).pack(
side=tk.TOP,
expand=True,
padx=22,
pady=11,
)
tk.Button(
self,
width=30,
text="Depositar",
command= lambda: self.jump_to_deposit(),
justify=tk.CENTER,
**style.text_style
).pack(
side=tk.TOP,
expand=True,
padx=22,
pady=11,
)
# Método para actualizar dinámicamente el saldo
def update_saldo(self):
self.label_saldo.config(text=f"Saldo actual: ${saldo:.2f}")
# Crear la pantalla de depósito
class deposit(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
self.configure(background=style.home_backg)
self.controller = controller
self.init_widgets_deposit()
# Definir el método para regresar al menú principal
def jump_to_home(self):
self.controller.show_frame(home)
# Definir el método para realizar un depósito
def depositar(self):
try:
# Obtener el monto ingresado
monto_ingresado = float(self.entry_deposit.get())
if monto_ingresado <= 0:
raise ValueError("El monto a depositar debe ser positivo.")
global saldo # Usa la variable global 'saldo'
saldo += monto_ingresado # Actualiza el saldo
# Mostrar mensaje de éxito
messagebox.showinfo(
"Depósito Exitoso",
f"Has depositado ${monto_ingresado:.2f}. Tu nuevo saldo es: ${saldo:.2f}",
)
self.label_saldo.config(text=f"Su Saldo :{saldo:.2f}")
self.entry_deposit.delete(0, tk.END) # Limpia la entrada
except ValueError as e:
# Mostrar error específico
messagebox.showerror("Error", "Por favor, ingrese sólo números.")
except Exception:
# Mostrar error genérico
messagebox.showerror("Error", "Por favor ingresa un monto válido.")
# Colocar los widgets en el frame de la clase depósito
def init_widgets_deposit(self):
self.label_saldo=tk.Label(
self,
text=f"Su Saldo :{saldo:.2f}",
justify=tk.CENTER,
**style.text_saldo
)
self.label_saldo.pack(
side=tk.TOP,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
tk.Label(
self,
text="Ingrese el monto a depositar: ",
justify=tk.CENTER,
**style.text_style
).pack(
side=tk.TOP,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
# Guardar entry_deposit como atributo de la instancia
self.entry_deposit = tk.Entry(self, font=('Arial', 15))
self.entry_deposit.pack(side=tk.TOP, fill=tk.X, expand=True, padx=22, pady=11)
tk.Button(
self,
text="Cancelar",
command=lambda: self.jump_to_home(),
justify=tk.LEFT,
**style.text_style
).pack(
side=tk.LEFT,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
tk.Button(
self,
text="Aceptar",
command=self.depositar, # Llama directamente a self.depositar
justify=tk.RIGHT,
**style.text_style
).pack(
side=tk.RIGHT,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
# Método para actualizar dinámicamente el saldo
def update_saldo(self):
self.label_saldo.config(text=f"Saldo actual: ${saldo:.2f}")
#Crear la pantalla de retiro
class withdraw(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
self.configure(background=style.home_backg)
self.controller = controller
self.init_widgets_deposit()
# Definir el método para regresar al menú principal
def jump_to_home(self):
self.controller.show_frame(home)
# Definir el método para realizar un retiro
def retirar(self):
try:
global saldo # Usa la variable global 'saldo'
# Obtener el monto ingresado
monto_ingresado = float(self.entry_deposit.get())
if monto_ingresado <= 0:
raise ValueError("El monto a retirar debe ser positivo.")
elif monto_ingresado > saldo:
raise ValueError("Fondos insuficientes.")
elif monto_ingresado > 0 and monto_ingresado < saldo:
saldo -= monto_ingresado # Actualiza el saldo
# Mostrar mensaje de éxito
messagebox.showinfo(
"Retiro Exitoso",
f"Has retirado ${monto_ingresado:.2f}. Tu nuevo saldo es: ${saldo:.2f}",
)
self.label_saldo.config(text=f"Su Saldo :{saldo:.2f}")
self.entry_deposit.delete(0, tk.END) # Limpia la entrada
except Exception:
# Mostrar error genérico
messagebox.showerror("Error", "Por favor ingresa un monto válido.")
# Colocar los widgets en el frame de la clase depósito
def init_widgets_deposit(self):
self.label_saldo=tk.Label(
self,
text=f"Su Saldo :{saldo:.2f}",
justify=tk.CENTER,
**style.text_saldo
)
self.label_saldo.pack(
side=tk.TOP,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
tk.Label(
self,
text="Ingrese el monto a retirar: ",
justify=tk.CENTER,
**style.text_style
).pack(
side=tk.TOP,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
# Guardar entry_deposit como atributo de la instancia
self.entry_deposit = tk.Entry(self, font=('Arial', 15))
self.entry_deposit.pack(side=tk.TOP, fill=tk.X, expand=True, padx=22, pady=11)
tk.Button(
self,
text="Cancelar",
command=lambda: self.jump_to_home(),
justify=tk.LEFT,
**style.text_style
).pack(
side=tk.LEFT,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
tk.Button(
self,
text="Aceptar",
command=self.retirar, # Llama directamente a self.depositar
justify=tk.RIGHT,
**style.text_style
).pack(
side=tk.RIGHT,
fill=tk.X,
expand=True,
padx=22,
pady=11,
)
# Método para actualizar dinámicamente el saldo
def update_saldo(self):
self.label_saldo.config(text=f"Saldo actual: ${saldo:.2f}")