-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaestro_perfil.py
More file actions
134 lines (114 loc) · 5.82 KB
/
Copy pathmaestro_perfil.py
File metadata and controls
134 lines (114 loc) · 5.82 KB
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
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
from funciones.conexion import conexion
import os
class MaestroPerfil:
def __init__(self, parent, id_usuario):
self.parent = parent
self.id_usuario = id_usuario # ID del maestro
self.setup_ui()
def setup_ui(self):
"""Configura la interfaz gráfica del perfil del maestro con diseño mejorado."""
# Crear un marco principal centrado con las dimensiones especificadas
frame = tk.Frame(self.parent, bg="#e9f3f5", bd=0)
frame.place(relx=0.5, rely=0.5, anchor="center", width=750, height=400) # Ajustar dimensiones
# Encabezado con un título elegante centrado
header_frame = tk.Frame(frame, bg="#004a8f", height=60) # Ajustar altura del encabezado
header_frame.pack(fill="x", side="top")
title_label = tk.Label(
header_frame, text="Perfil del Maestro", font=("Helvetica", 18, "bold"),
bg="#004a8f", fg="white", anchor="center"
)
title_label.pack(pady=10) # Añadir más espacio vertical para el título
# Contenedor del cuerpo
body_frame = tk.Frame(frame, bg="#ffffff", bd=2, relief="groove")
body_frame.pack(fill="both", expand=True, padx=20, pady=10)
# Sección superior: imagen de perfil
top_frame = tk.Frame(body_frame, bg="#ffffff")
top_frame.pack(pady=10)
# Imagen de perfil
self.cargar_imagen(top_frame)
# Contenedor para los campos de texto
details_frame = tk.Frame(body_frame, bg="#ffffff")
details_frame.pack(fill="both", expand=True, padx=15, pady=10)
# Obtener datos del maestro
self.obtener_datos_maestro()
# Crear las etiquetas y entradas de datos
self.create_label_and_entry(details_frame, "Código:", self.id_usuario, 0, True)
self.create_label_and_entry(details_frame, "Nombre:", self.nombre, 1)
self.create_label_and_entry(details_frame, "Email:", self.email, 2)
self.create_label_and_entry(details_frame, "Grado de Estudios:", self.grado_estudios, 3)
self.create_label_and_entry(details_frame, "Carrera:", self.nombre_carrera, 4)
self.create_label_and_entry(details_frame, "Materia:", self.nombre_materia, 5)
def cargar_imagen(self, frame):
"""Carga la imagen de perfil con bordes redondeados."""
try:
img_path = os.path.abspath("fotos/persona.png")
if not os.path.exists(img_path):
raise FileNotFoundError(f"No se encontró el archivo de imagen en: {img_path}")
img = Image.open(img_path)
img_resized = img.resize((90, 90), Image.LANCZOS)
self.photo = ImageTk.PhotoImage(img_resized)
img_label = tk.Label(frame, image=self.photo, bg="#ffffff", bd=0)
img_label.photo = self.photo
img_label.pack(pady=10)
except Exception as e:
print(f"Error al cargar la imagen: {e}")
def create_label_and_entry(self, parent, label_text, value, row, is_id=False):
"""Crea un diseño moderno para las etiquetas y entradas."""
# Contenedor para cada fila
row_frame = tk.Frame(parent, bg="#ffffff")
row_frame.pack(fill="x", pady=5)
# Etiqueta
label = tk.Label(
row_frame, text=label_text, font=("Helvetica", 12, "bold"),
bg="#ffffff", fg="#004a8f", anchor="w", width=20
)
label.pack(side="left", padx=10)
# Campo de texto
entry = tk.Entry(
row_frame, font=("Helvetica", 12), bg="#f0f8ff", fg="#333", relief="flat",
disabledbackground="#f0f8ff", disabledforeground="#333"
)
entry.pack(side="left", padx=10, fill="x", expand=True)
entry.insert(0, value)
entry.config(state="readonly")
def obtener_datos_maestro(self):
"""Obtiene los datos del maestro desde la base de datos."""
try:
db = conexion() # Conexión a la base de datos
conn = db.open()
cursor = conn.cursor()
print(f"ID de usuario recibido: {self.id_usuario}")
cursor.execute("SELECT Nombre, Email, Grado_de_estudios, carrera, materia FROM maestro WHERE Id = %s", (self.id_usuario,))
resultado = cursor.fetchone()
if resultado:
self.nombre, self.email, self.grado_estudios, carrera_id, materia_id = resultado
self.nombre_carrera = self.obtener_nombre_carrera(carrera_id, cursor)
self.nombre_materia = self.obtener_nombre_materia(materia_id, cursor)
else:
self.nombre = self.email = self.grado_estudios = self.nombre_carrera = self.nombre_materia = "No disponible"
except Exception as e:
print(f"Error al obtener datos: {e}")
self.nombre = self.email = self.grado_estudios = self.nombre_carrera = self.nombre_materia = "Error"
finally:
db.close()
def obtener_nombre_carrera(self, carrera_id, cursor):
"""Obtiene el nombre de la carrera a partir de su ID."""
try:
cursor.execute("SELECT Nombre FROM carrera WHERE Id = %s", (carrera_id,))
resultado = cursor.fetchone()
return resultado[0] if resultado else "No disponible"
except Exception as e:
print(f"Error al obtener nombre de la carrera: {e}")
return "Error"
def obtener_nombre_materia(self, materia_id, cursor):
"""Obtiene el nombre de la materia a partir de su ID."""
try:
cursor.execute("SELECT Asignatura FROM materia WHERE Id = %s", (materia_id,))
resultado = cursor.fetchone()
return resultado[0] if resultado else "No disponible"
except Exception as e:
print(f"Error al obtener nombre de la materia: {e}")
return "Error"