Skip to content

Commit b5d985f

Browse files
committed
QR
1 parent 1d530c6 commit b5d985f

13 files changed

+161
-0
lines changed

GUI QR/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
COLOR_BARRA_SUPERIOR_IZQ = "#ffffff"
2+
COLOR_BARRA_SUPERIOR_DER = "#f7f7f7"
3+
COLOR_BARRA_INFERIOR = "#2c2c2c"
4+
5+
COLOR_BOTON = "#4a9ef4"
6+
COLOR_TEXTO_BOTON = "#ffffff"

GUI QR/formulario/__init__.py

Whitespace-only changes.

GUI QR/formulario/escanea_me.png

21.3 KB
Loading

GUI QR/formulario/form_maestra.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import qrcode
2+
import tkinter as tk
3+
from tkinter import filedialog
4+
from PIL import Image, ImageTk, ImageDraw
5+
from formulario.form_maestra_design import FormMestroDesign
6+
7+
8+
class FormMestro(FormMestroDesign):
9+
10+
def __init__(self) -> None:
11+
super().__init__()
12+
13+
def on_entry_focus_in(self, event):
14+
if self.entrada_texto.get() == self.placeholder_text:
15+
self.entrada_texto.delete(0, tk.END)
16+
17+
def on_entry_focus_out(self, event):
18+
if not self.entrada_texto.get():
19+
self.entrada_texto.insert(0, self.placeholder_text)
20+
21+
def generar_qr_con_forma(self, texto):
22+
qr = qrcode.QRCode(
23+
version=1,
24+
error_correction=qrcode.constants.ERROR_CORRECT_L,
25+
box_size=10,
26+
border=4,
27+
)
28+
qr.add_data(texto)
29+
qr.make(fit=True)
30+
img = qr.make_image(fill_color="black", back_color="white")
31+
32+
return img
33+
34+
def on_button_click_mostrar_qr(self):
35+
texto = self.entrada_texto.get()
36+
qr_image = self.generar_qr_con_forma(texto)
37+
img_tk = ImageTk.PhotoImage(qr_image)
38+
self.etiqueta_qr.config(image=img_tk)
39+
self.etiqueta_qr.image = img_tk
40+
self.qr_guardado = qr_image
41+
42+
def on_button_click_guardar_qr(self):
43+
archivo = filedialog.asksaveasfilename(
44+
defaultextension=".png", filetypes=[("Archivos PNG", "*.png")])
45+
if archivo:
46+
self.qr_guardado.save(archivo)
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
import util.util_ventana as util_ven
4+
from PIL import Image, ImageTk, ImageDraw
5+
import util.util_imagenes as util_img
6+
import config as conf
7+
8+
9+
class FormMestroDesign(tk.Tk):
10+
11+
def __init__(self) -> None:
12+
super().__init__()
13+
self.qr_guardado = None
14+
self.qr_img_base = util_img.leer_imagen("./imagenes/qr_base.png", (330, 330))
15+
self.qr_mensaje = util_img.leer_imagen("./imagenes/escanea_me.png", (300, 200))
16+
self.config_window()
17+
self.paneles()
18+
self.widget_panel_superior()
19+
self.widget_panel_inferior()
20+
21+
def config_window(self):
22+
self.title('QR Diseño de Código')
23+
self.iconbitmap("./imagenes/logo.ico")
24+
w, h = 800, 450
25+
util_ven.centrar_ventana(self, w, h)
26+
27+
def paneles(self):
28+
29+
self.barra_superior = tk.Frame(self,)
30+
self.barra_superior.pack(side=tk.TOP, fill='both', expand=True)
31+
32+
self.barra_superior_izq = tk.Frame(
33+
self.barra_superior, bg=conf.COLOR_BARRA_SUPERIOR_IZQ)
34+
self.barra_superior_izq.pack(side=tk.LEFT, fill='both', expand=True)
35+
self.barra_superior_der = tk.Frame(
36+
self.barra_superior, bg=conf.COLOR_BARRA_SUPERIOR_DER)
37+
self.barra_superior_der.pack(side=tk.RIGHT, fill='both', expand=True)
38+
39+
self.barra_inferior = tk.Frame(
40+
self, bg=conf.COLOR_BARRA_INFERIOR, height=50)
41+
self.barra_inferior.pack(side=tk.BOTTOM, fill='x', expand=False)
42+
43+
def widget_panel_superior(self):
44+
45+
self.labelTitulo = tk.Label(
46+
self.barra_superior_izq, text="QR Diseño de Código", bg=conf.COLOR_BARRA_SUPERIOR_IZQ)
47+
self.labelTitulo.config(fg="#000000", font=(
48+
"Roboto", 18, "bold"), pady=10, width=16)
49+
self.labelTitulo.pack(side=tk.TOP, expand=False, pady=20)
50+
51+
estilo = ttk.Style()
52+
estilo.configure("EstiloEntry.TEntry", padding=(
53+
10, 5, 10, 5), relief="flat")
54+
55+
self.entrada_texto = ttk.Entry(
56+
self.barra_superior_izq, width=50, style="EstiloEntry.TEntry")
57+
self.entrada_texto.pack(side=tk.TOP, expand=False, pady=20)
58+
59+
self.placeholder_text = "https://autodidacta.mx/"
60+
self.entrada_texto.insert(0, self.placeholder_text)
61+
self.entrada_texto.bind("<FocusIn>", self.on_entry_focus_in)
62+
self.entrada_texto.bind("<FocusOut>", self.on_entry_focus_out)
63+
64+
self.etiqueta_mensaje = ttk.Label(self.barra_superior_izq, image=self.qr_mensaje, border=100)
65+
self.etiqueta_mensaje.pack(side=tk.TOP, expand=True, pady=20, padx=20)
66+
67+
self.etiqueta_qr = ttk.Label(self.barra_superior_der,image=self.qr_img_base)
68+
self.etiqueta_qr.pack(side=tk.TOP, expand=True, pady=20, padx=20)
69+
70+
71+
def on_entry_focus_in(self, event):
72+
pass
73+
74+
def on_entry_focus_out(self, event):
75+
pass
76+
77+
def widget_panel_inferior(self):
78+
79+
self.boton_generar = tk.Button(self.barra_inferior, text="Generar Codigo", width=15, height=2,
80+
bg=conf.COLOR_BOTON, fg=conf.COLOR_TEXTO_BOTON, relief=tk.FLAT, padx=5, pady=5, bd=0, borderwidth=0, highlightthickness=0,
81+
overrelief='flat', command=self.on_button_click_mostrar_qr)
82+
self.boton_generar.pack(side=tk.RIGHT, expand=False, padx=10, pady=10)
83+
84+
self.boton_descargar = tk.Button(self.barra_inferior, text="Descargar Codigo", width=15, height=2,
85+
bg=conf.COLOR_BOTON, fg=conf.COLOR_TEXTO_BOTON, relief=tk.FLAT, padx=5, pady=5, bd=0, borderwidth=0, highlightthickness=0,
86+
overrelief='flat', command=self.on_button_click_guardar_qr)
87+
self.boton_descargar.pack(
88+
side=tk.RIGHT, expand=False, padx=10, pady=10)
89+
90+
def on_button_click_mostrar_qr(self):
91+
pass
92+
93+
def on_button_click_guardar_qr(self):
94+
pass

GUI QR/imagenes/escanea_me.png

21.3 KB
Loading

GUI QR/imagenes/logo.ico

263 KB
Binary file not shown.

GUI QR/imagenes/qr_base.png

5.31 KB
Loading

GUI QR/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from formulario.form_maestra import FormMestro
2+
3+
app = FormMestro()
4+
app.mainloop()

GUI QR/requirements.txt

192 Bytes
Binary file not shown.

GUI QR/util/__init__.py

Whitespace-only changes.

GUI QR/util/util_imagenes.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from PIL import ImageTk, Image
2+
3+
def leer_imagen( path, size):
4+
return ImageTk.PhotoImage(Image.open(path).resize(size, Image.ADAPTIVE))
5+

GUI QR/util/util_ventana.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def centrar_ventana(ventana,aplicacion_ancho,aplicacion_largo):
2+
pantall_ancho = ventana.winfo_screenwidth()
3+
pantall_largo = ventana.winfo_screenheight()
4+
x = int((pantall_ancho/2) - (aplicacion_ancho/2))
5+
y = int((pantall_largo/2) - (aplicacion_largo/2))
6+
return ventana.geometry(f"{aplicacion_ancho}x{aplicacion_largo}+{x}+{y}")

0 commit comments

Comments
 (0)