-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_to_encode_base64.py
More file actions
39 lines (32 loc) · 1.41 KB
/
file_to_encode_base64.py
File metadata and controls
39 lines (32 loc) · 1.41 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
import tkinter as tk
from tkinter import filedialog, messagebox
from base64 import b64encode
def seleccionar_archivo():
ruta = filedialog.askopenfilename()
if ruta:
try:
with open(ruta, "rb") as archivo:
codificado = b64encode(archivo.read()).decode()
texto_resultado.delete("1.0", tk.END)
texto_resultado.insert(tk.END, codificado)
except Exception as e:
messagebox.showerror("Error", f"No se pudo codificar el archivo:\n{e}")
def copiar_al_portapapeles():
resultado = texto_resultado.get("1.0", tk.END).strip()
if resultado:
ventana.clipboard_clear()
ventana.clipboard_append(resultado)
ventana.update()
messagebox.showinfo("Copiado", "El texto codificado fue copiado al portapapeles.")
else:
messagebox.showwarning("Vacío", "No hay nada que copiar.")
ventana = tk.Tk()
ventana.title("Codificador Base64 de Archivos")
ventana.geometry("800x600")
boton_seleccionar = tk.Button(ventana, text="Seleccionar archivo", command=seleccionar_archivo)
boton_seleccionar.pack(pady=10)
texto_resultado = tk.Text(ventana, wrap=tk.WORD, height=25)
texto_resultado.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
boton_copiar = tk.Button(ventana, text="Copiar al portapapeles", command=copiar_al_portapapeles)
boton_copiar.pack(pady=10)
ventana.mainloop()