-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.PY
More file actions
71 lines (55 loc) · 2.98 KB
/
Copy pathGUI.PY
File metadata and controls
71 lines (55 loc) · 2.98 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
from tkinter import *
from tkinter import filedialog
#Aqui te ayuda para encontrar el archivo, para que lo puedas seleccionar,
#se abre una ventana donde esta solo clasificado para archivos tipo txt
def leer():
global filename
filetypes = [('Archivos TXT', '*.txt')]
filename = filedialog.askopenfilename(filetypes=filetypes)
if filename:
try:
#ESTO ESPECIFICA QUE EL R, ES SOLO PARA LEER LOS DATOS DEL ARCHVIO SIN MODIFICARLO, Y EL UTF-8 ES PARA QUE PUEDA LEER UNA GRAN VARIEDAD DE CARACTERES
#LO ESPECIFIQUE PORQUE NO ME DEJABA LEER EL ARCHIVO DEL PROFE
with open(filename, 'r', encoding='utf-8') as file:
contenido = file.read()
conteo(contenido)
#ESTO SE PONE POR SI HAY ALGUN ERROR EN LA CODIFICACIÓN DE LA CANTIDAD DE LETRAS REPETIDS
except UnicodeDecodeError as e:
print(f"Error al decodificar el archivo: {e}")
#CREO QUE UNA VARIABLE GLOBAL DONDE GUARDO EN UN DICCIOANRIO LOS DATOS DE REPETICONES DEL ARCHVIO TXT
#ESTO LO HICE PARA QUE SEA MÁS FACIL UTILIZAR ESTA VARIABLE EN FUNCIONES PARA MANIPULAR
contador_letras = {}
def conteo(letras):
global contador_letras#AQUI MARCO LA VARIABLE COMO GLOBAL, ESTO SIGNIFICA QUE SI MODIFICAS LOS VALORES
#EN ESTA FUNCIÓN, Y LA TIENES O LA LLAMAS EN OTRA FUNCIÓN, ESTA SERÁ EXACTAMENTE LA MISMA
#AHOAR BIEN, EN LA LINEA DE ABAJO HACE ALGO CURIOSO, DETECTA LA LETRA Y EN EL ARCHIVO, SI ESTA EN EL DICIIONARIO, LE SUMA UNO
#Si no se encuentra, este se guarda como nuevo valor
for letra in letras:
if letra in contador_letras:
contador_letras[letra] += 1
else:
contador_letras[letra] = 1
print(contador_letras)
#Aquí solo va insertra en el cuadro de texto, los valores que almacenó el diccioanrio
CuadroTexto.insert(END,"El resumen de las letras son:\n")
for clave,valor in contador_letras.items():
CuadroTexto.insert(END, f"{clave}: {valor}\n")
Raiz = Tk()
Raiz.title('Actividad 07')
Raiz.config(width=700, height=600)
MFrame = Frame(Raiz)
MFrame.config(width=500, height=200, bg="#757575")
MFrame.pack()
BotonLeer=Button(MFrame, text="Examinar",command=leer,bg="#0B656C",fg="#FFFFFF")
BotonLeer.place(x=10,y=75, width=115,height=25)
BotonComprimir=Button(MFrame, text="Comprimir",bg="#0B476C",fg="#FFFFFF")
BotonComprimir.place(x=10,y=105, width=115,height=25)
BotonDescomprimir=Button(MFrame, text="Descomprimir",bg="#0B476C",fg="#FFFFFF")
BotonDescomprimir.place(x=10,y=135, width=115,height=25)
CuadroTexto=Text(MFrame)
CuadroTexto.place(x=130,y=45,width=350,height=145)
BotonComprimir = Button(MFrame, text="Comprimir", command="AQUI PON LA FUNCIÓN DE COMPRIMIR", bg="#0B476C", fg="#FFFFFF")
BotonComprimir.place(x=10, y=105, width=115, height=25)
BotonDescomprimir = Button(MFrame, text="Descomprimir", command="AQUI PON LA FUNCIÓN DE DESCOMPRIMIR", bg="#0B476C", fg="#FFFFFF")
BotonDescomprimir.place(x=10, y=135, width=115, height=25)
Raiz.mainloop()