-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexam_validator.py
More file actions
610 lines (519 loc) · 27.4 KB
/
exam_validator.py
File metadata and controls
610 lines (519 loc) · 27.4 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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
import tkinter as tk
from tkinter import filedialog, messagebox, scrolledtext, ttk
import zipfile
import os
import tempfile
import shutil
from localization import LocalizationManager
import traceback
# --- CLASE PRINCIPAL: ExamValidator ---
class ExamValidator:
def __init__(self, root):
self.root = root
self.lang_manager = LocalizationManager()
self.root.geometry("1000x800")
self.root.minsize(800, 600)
self.root.grid_columnconfigure(0, weight=1)
self.root.grid_rowconfigure(0, weight=1)
self.zip_path = None
self.reference_folder = None
self.temp_dir = None
self.setup_menu()
self.setup_ui()
self.update_ui_text()
def setup_menu(self):
"""Crea la barra de menú."""
menubar = tk.Menu(self.root)
self.root.config(menu=menubar)
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(menu=file_menu, label=self.lang_manager.get_string("menu_file"))
file_menu.add_command(label=self.lang_manager.get_string("menu_file_zip"), command=self.select_zip)
file_menu.add_command(label=self.lang_manager.get_string("menu_file_ref"), command=self.select_reference)
file_menu.add_separator()
file_menu.add_command(label=self.lang_manager.get_string("menu_file_exit"), command=self.root.quit)
lang_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(menu=lang_menu, label=self.lang_manager.get_string("menu_lang"))
lang_menu.add_command(label=self.lang_manager.get_string("menu_lang_es"),
command=lambda: self.set_language('es'))
lang_menu.add_command(label=self.lang_manager.get_string("menu_lang_en"),
command=lambda: self.set_language('en'))
self.menubar = menubar
def set_language(self, lang_code):
"""Cambia el idioma y actualiza la UI."""
if self.lang_manager.set_language(lang_code):
self.update_ui_text()
self.setup_menu()
def update_ui_text(self):
"""Actualiza todos los textos estáticos de la UI."""
self.root.title(self.lang_manager.get_string("window_title"))
self.title_label.config(text=self.lang_manager.get_string("title"))
self.label_step1.config(text=self.lang_manager.get_string("step1"))
self.label_step2.config(text=self.lang_manager.get_string("step2"))
if not self.zip_path:
self.zip_label.config(text=self.lang_manager.get_string("zip_none"))
if not self.reference_folder:
self.ref_label.config(text=self.lang_manager.get_string("ref_none"))
self.btn_zip.config(text=self.lang_manager.get_string("button_browse"))
self.btn_ref.config(text=self.lang_manager.get_string("button_browse"))
self.validate_btn.config(text=self.lang_manager.get_string("button_validate"))
self.label_results.config(text=self.lang_manager.get_string("results_title"))
def setup_ui(self):
"""Configura la interfaz principal con adaptabilidad y prioridad en el área del log."""
main_frame = ttk.Frame(self.root, padding="20 10 20 10")
main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
main_frame.grid_columnconfigure(1, weight=1)
main_frame.grid_columnconfigure(0, weight=0)
main_frame.grid_columnconfigure(2, weight=0)
main_frame.grid_rowconfigure(6, weight=1)
# Título
self.title_label = ttk.Label(main_frame, text="", font=('Arial', 18, 'bold'), anchor='center')
self.title_label.grid(row=0, column=0, columnspan=3, pady="10 15", sticky=(tk.W, tk.E))
ttk.Separator(main_frame, orient=tk.HORIZONTAL).grid(row=1, column=0, columnspan=3, sticky=(tk.W, tk.E),
pady="0 10")
# 1. Seleccionar ZIP
self.label_step1 = ttk.Label(main_frame, text="", font=('Arial', 10, 'bold'))
self.label_step1.grid(row=2, column=0, sticky=tk.W, pady=5, padx="0 10")
self.zip_label = ttk.Label(main_frame, text="", foreground="gray", anchor=tk.W, relief=tk.GROOVE,
padding="5 3")
self.zip_label.grid(row=2, column=1, sticky=(tk.W, tk.E), padx=5)
self.btn_zip = ttk.Button(main_frame, text="Examinar...", command=self.select_zip)
self.btn_zip.grid(row=2, column=2, padx="10 0")
# 2. Carpeta de referencia
self.label_step2 = ttk.Label(main_frame, text="", font=('Arial', 10, 'bold'))
self.label_step2.grid(row=3, column=0, sticky=tk.W, pady=5, padx="0 10")
self.ref_label = ttk.Label(main_frame, text="", foreground="gray", anchor=tk.W, relief=tk.GROOVE,
padding="5 3")
self.ref_label.grid(row=3, column=1, sticky=(tk.W, tk.E), padx=5)
self.btn_ref = ttk.Button(main_frame, text="Examinar...", command=self.select_reference)
self.btn_ref.grid(row=3, column=2, padx="10 0")
# Botón de validación
self.validate_btn = ttk.Button(main_frame, text="",
command=self.validate_exam, state=tk.DISABLED,
style='Accent.TButton')
self.validate_btn.grid(row=4, column=0, columnspan=3, pady="20 15",
sticky=(tk.W, tk.E))
# Resultados Título
self.label_results = ttk.Label(main_frame, text="", font=('Arial', 12, 'bold'))
self.label_results.grid(row=5, column=0, columnspan=3, sticky=tk.W, pady="15 5")
# Área de Visualización del Log (ScrolledText)
self.results_text = scrolledtext.ScrolledText(main_frame, wrap=tk.WORD,
font=('Courier', 10), relief=tk.SUNKEN)
self.results_text.grid(row=6, column=0, columnspan=3, pady="5 0",
sticky=(tk.W, tk.E, tk.N, tk.S))
# Configuración de Tags
self.results_text.tag_config("error", foreground="red", font=('Courier', 10, 'bold'))
self.results_text.tag_config("warning", foreground="#FF4500", font=('Courier', 10, 'bold'))
self.results_text.tag_config("success", foreground="green", font=('Courier', 10, 'bold'))
self.results_text.tag_config("info", foreground="blue", font=('Courier', 10, 'normal'))
self.results_text.tag_config("header", font=('Courier', 11, 'bold'))
try:
style = ttk.Style()
style.theme_use('clam')
style.configure('Accent.TButton', font=('Arial', 12, 'bold'), background='#0078D4', foreground='black')
except Exception:
pass
def select_zip(self):
filename = filedialog.askopenfilename(
title=self.lang_manager.get_string("menu_file_zip"),
filetypes=[("Archivos ZIP", "*.zip"), ("Todos los archivos", "*.*")]
)
if filename:
self.zip_path = filename
display_text = os.path.basename(filename)
self.zip_label.config(text=display_text, foreground="black")
self.validate_btn.config(state=tk.NORMAL)
def select_reference(self):
dirname = filedialog.askdirectory(title=self.lang_manager.get_string("menu_file_ref"))
if dirname:
self.reference_folder = dirname
display_text = os.path.basename(dirname)
self.ref_label.config(text=display_text, foreground="black")
# Métodos de cálculo de hash y parsing
def calculate_file_hash(self, content):
hash_value = 29366927
if isinstance(content, str):
content = content.encode('utf-8')
for i, byte in enumerate(content):
mult = 1 if (i % 2) == 0 else 100
signed_byte = byte if byte < 128 else byte - 256
hash_value += signed_byte * mult
return hash_value
def calculate_resume_hash(self, zip_path, student_name, log_messages):
hash_value = 29366927
name_bytes = student_name.encode('utf-8')
for i, byte in enumerate(name_bytes):
mult = 1 if (i % 2) == 0 else 100
signed_byte = byte if byte < 128 else byte - 256
hash_value += signed_byte * mult
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
all_files = sorted([f for f in zip_ref.infolist() if not f.is_dir()],
key=lambda x: x.filename)
for file_info in all_files:
file_name = file_info.filename
if file_name.endswith('resume.txt'):
continue
position = 0
with zip_ref.open(file_name) as f:
while True:
buffer = f.read(4096)
if not buffer:
break
for i, byte in enumerate(buffer):
global_pos = position + i
mult = 1 if (global_pos % 2) == 0 else 100
signed_byte = byte if byte < 128 else byte - 256
hash_value += signed_byte * mult
position += len(buffer)
hash_value += len(log_messages)
return hash_value
def parse_resume(self, content):
lines = content.split('\n')
student_name = lines[0].strip() if lines else ""
num_files = 0
declared_hash = 0
log_messages = []
in_log_section = False
for line in lines:
if 'Num files:' in line:
try:
num_files = int(line.split(':')[1].strip())
except:
pass
elif 'Hash Value:' in line:
try:
declared_hash = int(line.split(':')[1].strip())
except:
pass
elif 'Log messages:' in line:
in_log_section = True
elif in_log_section and line.strip() and 'Hash Value:' not in line:
log_messages.append(line.strip())
return {
'student_name': student_name,
'num_files': num_files,
'declared_hash': declared_hash,
'log_messages': log_messages
}
def extract_initial_snapshot(self, log_messages, project_folder):
snapshot = {}
in_snapshot = False
for msg in log_messages:
if '=== Initial folder snapshot:' in msg:
in_snapshot = True
continue
if '=== End of snapshot ===' in msg:
break
if in_snapshot and msg.startswith('File:'):
parts = msg.split('|')
if len(parts) >= 3:
file_path = parts[0].replace('File:', '').strip()
try:
size = int(parts[1].split(':')[1].strip().replace('bytes', '').strip())
lines = int(parts[2].split(':')[1].strip())
file_path = os.path.normpath(file_path)
project_folder = os.path.normpath(project_folder)
if file_path.startswith(project_folder):
rel_path = os.path.relpath(file_path, project_folder)
snapshot[rel_path] = {
'size': size,
'lines': lines,
'path': file_path
}
except:
pass
return snapshot
def extract_backup_hashes(self, log_messages):
backup_files = {}
for msg in log_messages:
if 'FILE COPIED:' in msg and 'Hash:' in msg and 'Backup:' in msg:
try:
hash_part = msg.split('Hash:')[1].split('|')[0].strip()
expected_hash = int(hash_part)
backup_part = msg.split('Backup:')[1].strip()
file_name = os.path.basename(backup_part)
backup_files[file_name] = expected_hash
except:
pass
return backup_files
def analyze_log_activity(self, log_messages):
total_suspicious_lines = 0
suspicious_events = []
network_events = []
unauthorized_app_events = []
for msg in log_messages:
# --- 1. Actividad Sospechosa (Red Activa + Cambios) ---
if '[SUSPICIOUS: network was active]' in msg:
if '.copywatcher_backup' in msg:
continue
suspicious_events.append(msg)
if 'MODIFIED:' in msg:
if 'lines:' in msg:
try:
lines_part = msg.split('lines:')[1].split(']')[0]
if '[' in lines_part:
change = lines_part.split('[')[0].strip()
change_value = int(change.replace('+', '').replace('-', ''))
if change_value != 0:
total_suspicious_lines += abs(change_value)
suspicious_events.append(msg)
except:
pass
elif 'NEW FILE:' in msg:
try:
if 'lines)' in msg:
lines_part = msg.split('lines)')[0].split(',')[-1].strip()
lines_count = int(lines_part.split()[0])
if lines_count > 0:
total_suspicious_lines += lines_count
suspicious_events.append(msg)
except:
pass
# --- 2. Detección de conexión aunque no haya cambiado nada ---
if "Network connection detected" in msg or "Conexión a red detectada" in msg or "Conexion a red detectada" in msg:
network_events.append(msg)
# --- 3. Aplicaciones no autorizadas ---
if ' - Detectado ' in msg and ' - Cierre el programa' in msg:
unauthorized_app_events.append(msg)
# Versión en inglés
if ' - Detected ' in msg and ' - Close the program' in msg:
unauthorized_app_events.append(msg)
return total_suspicious_lines, suspicious_events, network_events, unauthorized_app_events
def compare_with_reference(self, snapshot, reference_folder):
differences = []
reference_files = {}
for root, dirs, files in os.walk(reference_folder):
for file in files:
file_path = os.path.join(root, file)
rel_path = os.path.relpath(file_path, reference_folder)
try:
actual_size = os.path.getsize(file_path)
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
actual_lines = len(f.readlines())
reference_files[os.path.normpath(rel_path)] = {
'size': actual_size,
'lines': actual_lines
}
except:
pass
for rel_path, expected in snapshot.items():
if rel_path in reference_files:
actual = reference_files[rel_path]
if actual['size'] != expected['size'] or actual['lines'] != expected['lines']:
differences.append({
'file': rel_path,
'expected_size': expected['size'],
'actual_size': actual['size'],
'expected_lines': expected['lines'],
'actual_lines': actual['lines']
})
else:
differences.append({
'file': rel_path,
'expected_size': expected['size'],
'actual_size': 'N/A',
'expected_lines': expected['lines'],
'actual_lines': 'N/A'
})
return differences
def validate_backup_files(self, backup_folder, expected_hashes):
results = []
for file_name, expected_hash in expected_hashes.items():
file_path = os.path.join(backup_folder, file_name)
if os.path.exists(file_path):
try:
with open(file_path, 'rb') as f:
content = f.read()
calculated_hash = self.calculate_file_hash(content)
matches = calculated_hash == expected_hash
results.append({
'file': file_name,
'expected': expected_hash,
'calculated': calculated_hash,
'matches': matches
})
except Exception as e:
results.append({
'file': file_name,
'error': str(e)
})
else:
results.append({
'file': file_name,
'error': 'Archivo no encontrado en backup'
})
return results
def find_backup_folder(self, root_dir):
for root, dirs, files in os.walk(root_dir):
if '.copywatcher_backup' in dirs:
return os.path.join(root, '.copywatcher_backup')
return None
# --- MÉTODO PRINCIPAL DE VALIDACIÓN ---
def validate_exam(self):
self.results_text.delete(1.0, tk.END)
if not self.zip_path:
messagebox.showerror(self.lang_manager.get_string("window_title"),
self.lang_manager.get_string("error_zip_select"))
return
critical_error = False
try:
self.temp_dir = tempfile.mkdtemp()
self.log(self.lang_manager.get_string("log_extracting") + "\n", "info")
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
zip_ref.extractall(self.temp_dir)
resume_path = None
project_folder = None
for root, dirs, files in os.walk(self.temp_dir):
if 'resume.txt' in files:
resume_path = os.path.join(root, 'resume.txt')
project_folder = os.path.dirname(resume_path)
break
if not resume_path:
self.log(self.lang_manager.get_string("log_error_resume") + "\n", "error")
critical_error = True
return
with open(resume_path, 'r', encoding='utf-8') as f:
resume_content = f.read()
parsed = self.parse_resume(resume_content)
# 1. INFORMACIÓN DEL ESTUDIANTE
self.log(self.lang_manager.get_string("log_info_header"), "header")
self.log(self.lang_manager.get_string("log_name", parsed['student_name']) + "\n", "info")
start_time = None
for msg in parsed['log_messages']:
if 'Project folder selected:' in msg:
start_time = msg.split(' - ')[0]
break
if start_time:
self.log(self.lang_manager.get_string("log_start_time", start_time), "info")
# 2. VALIDACIÓN DE HASH
self.log(self.lang_manager.get_string("log_hash_header"), "header")
calculated_hash = self.calculate_resume_hash(self.zip_path, parsed['student_name'], parsed['log_messages'])
hash_matches = calculated_hash == parsed['declared_hash']
if hash_matches:
self.log(self.lang_manager.get_string("log_hash_ok"), "success")
self.log(self.lang_manager.get_string("log_hash_declared", parsed['declared_hash']) + "\n")
self.log(self.lang_manager.get_string("log_hash_calculated", calculated_hash) + "\n\n")
else:
self.log(self.lang_manager.get_string("log_hash_error"), "error")
self.log(self.lang_manager.get_string("log_hash_declared", parsed['declared_hash']) + "\n", "error")
self.log(self.lang_manager.get_string("log_hash_calculated", calculated_hash) + "\n", "error")
self.log(self.lang_manager.get_string("log_hash_diff",
abs(calculated_hash - parsed['declared_hash'])) + "\n", "error")
critical_error = True
# 3. COMPARACIÓN DE SNAPSHOT INICIAL
self.log(self.lang_manager.get_string("log_snapshot_header"), "header")
snapshot = self.extract_initial_snapshot(parsed['log_messages'], project_folder)
self.log(self.lang_manager.get_string("log_snapshot_files", len(snapshot)) + "\n")
if self.reference_folder:
self.log(self.lang_manager.get_string("log_comparing_ref") + "\n", "info")
differences = self.compare_with_reference(snapshot, self.reference_folder)
if differences:
self.log(self.lang_manager.get_string("log_diff_count_error", len(differences)) + "\n", "warning")
for diff in differences:
self.log(self.lang_manager.get_string("log_diff_file", diff['file']) + "\n", "warning")
self.log(self.lang_manager.get_string("log_diff_size", diff['expected_size'],
diff['actual_size']) + "\n")
self.log(self.lang_manager.get_string("log_diff_lines", diff['expected_lines'],
diff['actual_lines']) + "\n")
critical_error = True
else:
self.log(self.lang_manager.get_string("log_snapshot_ok"), "success")
else:
self.log(self.lang_manager.get_string("log_no_ref"), "warning")
# 4. VALIDACIÓN DE ARCHIVOS DE BACKUP
self.log(self.lang_manager.get_string("log_backup_header"), "header")
backup_folder = self.find_backup_folder(self.temp_dir)
backup_hashes = self.extract_backup_hashes(parsed['log_messages'])
self.log(self.lang_manager.get_string("log_backup_expected", len(backup_hashes)) + "\n")
if not backup_hashes:
if not backup_folder:
self.log(self.lang_manager.get_string("log_backup_found_none"), "info")
else:
self.log(self.lang_manager.get_string("log_backup_folder_error"), "warning")
elif backup_folder:
validation_results = self.validate_backup_files(backup_folder, backup_hashes)
failed = [r for r in validation_results if not r.get('matches', False) and 'error' not in r]
errors = [r for r in validation_results if 'error' in r]
if failed or errors:
self.log(self.lang_manager.get_string("log_backup_count_error", len(failed) + len(errors)) + "\n",
"error")
for result in errors:
self.log(self.lang_manager.get_string("log_backup_file_error", result['file'],
result['error']) + "\n", "error")
for result in failed:
self.log(
self.lang_manager.get_string("log_backup_hash_error", result['file'], result['expected'],
result['calculated']) + "\n", "error")
critical_error = True
else:
self.log(self.lang_manager.get_string("log_backup_ok"), "success")
else:
self.log(self.lang_manager.get_string("log_backup_folder_error"), "error")
critical_error = True
# Obtener todos los eventos de actividad
suspicious_lines, suspicious_events, network_events, unauthorized_app_events = self.analyze_log_activity(
parsed['log_messages'])
# 5. ACTIVIDAD SOSPECHOSA (INTERNET ACTIVO)
self.log(self.lang_manager.get_string("log_suspicious_header"), "header")
self.log(self.lang_manager.get_string("log_suspicious_lines", suspicious_lines) + "\n")
if suspicious_lines > 0 or len(suspicious_events) > 0:
self.log(self.lang_manager.get_string("log_suspicious_limit_error") + "\n", "error")
self.log(self.lang_manager.get_string("log_suspicious_events_count", len(suspicious_events)) + "\n",
"warning")
if suspicious_events:
self.log(self.lang_manager.get_string("log_suspicious_event"), "warning")
for event in suspicious_events:
self.log(self.lang_manager.get_string("log_suspicious_event_item", event) + "\n", "warning")
critical_error = True
else:
self.log(self.lang_manager.get_string("log_suspicious_ok"), "success")
self.log(self.lang_manager.get_string("log_network_header"), "header")
if network_events:
self.log(self.lang_manager.get_string("log_network_count", len(network_events)) + "\n", "warning")
for event in network_events:
self.log(self.lang_manager.get_string("log_network_item", event) + "\n", "warning")
critical_error = True
else:
self.log(self.lang_manager.get_string("log_network_ok"), "success")
# 6. APLICACIONES NO AUTORIZADAS DETECTADAS
self.log(self.lang_manager.get_string("log_unauthorized_app_header"), "header")
if unauthorized_app_events:
self.log(
self.lang_manager.get_string("log_unauthorized_app_count", len(unauthorized_app_events)) + "\n",
"warning")
for event in unauthorized_app_events:
self.log(self.lang_manager.get_string("log_unauthorized_app_item", event) + "\n", "warning")
# Las detecciones de apps no autorizadas son un error crítico
critical_error = True
else:
self.log(self.lang_manager.get_string("log_unauthorized_app_ok"), "success")
# 7. RESUMEN FINAL
self.log("\n" + self.lang_manager.get_string("log_summary_header"), "header")
has_backups = False
if 'backup_hashes' in locals() and backup_hashes:
has_backups = len(backup_hashes) > 0
if critical_error:
self.log(self.lang_manager.get_string("log_summary_error"), "error")
elif has_backups:
self.log(self.lang_manager.get_string("log_summary_warning"), "warning")
else:
self.log(self.lang_manager.get_string("log_summary_ok"), "success")
except Exception as e:
self.log(self.lang_manager.get_string("log_general_error", str(e)), "error")
self.log(traceback.format_exc(), "error")
finally:
if self.temp_dir and os.path.exists(self.temp_dir):
try:
shutil.rmtree(self.temp_dir)
except:
pass
def log(self, message, tag=None):
if tag:
self.results_text.insert(tk.END, message, tag)
else:
self.results_text.insert(tk.END, message)
self.results_text.see(tk.END)
self.root.update_idletasks()
if __name__ == "__main__":
root = tk.Tk()
app = ExamValidator(root)
root.mainloop()