-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqr_generator.py
115 lines (79 loc) · 3.13 KB
/
qr_generator.py
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
import tkinter as tk;
from tkinter import ttk;
from tkinter import messagebox as mb
from PIL import ImageTk, Image;
import os;
import qrcode;
#
# In this class, we create a view for our application
# where the user will enter the data that the qr code will contain.
#
# Author: Edgard Díaz
#
class view:
def genera_code(self,frame,SSID,Seguridad, Password,Visibilidad):
if SSID != "" and Password != "":
if Visibilidad == "Si":
Visibilidad = "true";
else:
Visibilidad = "false";
qr = qrcode.QRCode(
version = 1,
error_correction = qrcode.constants.ERROR_CORRECT_Q, #About 35% or less errors can be corrected.
box_size = 6,
border = 2,
)
qr.add_data('WIFI:T:'+Seguridad+';S:'+SSID+';P:'+Password+';H:'+Visibilidad+';'); #Url or information that will contain the qr code.
qr.make(fit = True);
img = qr.make_image(fill_color = "black", black_color = "black");
output = open("output2.png", "wb");
img.save(output);
self.QR_Show(frame)
output.close();
else:
mb.showerror("Cuidado","Llene todos los campos");
def QR_Show(self,f):
self.canvas = tk.Canvas(f, width = 280, height = 280, bg = "white");
self.canvas.place(x = 7, y = 10);
self.img = tk.PhotoImage(file="output2.png");
self.canvas.create_image(140,140, image = self.img);
def ViewGenerateQR(self):
ventana = tk.Tk();
ventana.resizable(0,0);
ventana.title("QR Generator 1.0")
#Frame que contendra el codigo QR generado
f = tk.Frame(ventana, bg = "white", bd = 1, width = 300, height = 300);
f.grid(row=0, column=0, sticky ="NW");
f.grid_propagate(0)
f.update()
#Frame que contiene los campos requeridos para generar el QR
f2 = tk.Frame(ventana, bd = 1, width = 300, height = 150);
f2.grid(row=1, column=0, sticky ="NW");
f2.grid_propagate(0)
f2.update()
#componentes del Frame 2
lblSSID = tk.Label(f2, text = "SSID: ", font =("Verdana",12));
lblSSID.place(x = 42 ,y = 15, anchor = "center");
txtSSID = tk.Entry(f2);
txtSSID.place(x = 120, y = 0, width=145);
lblSeg = tk.Label(f2, text = "Seguridad:", font =("verdana", 12));
lblSeg.place(x = 60, y = 40, anchor ="center");
cbxSeg = ttk.Combobox(f2,state="readonly",values=["Ninguna","WPA","WEP"])
cbxSeg.current(1)
cbxSeg.place(x = 120, y = 25);
lblPwd= tk.Label(f2, text = "Contraseña:", font =("verdana", 12));
lblPwd.place(x = 65, y = 65, anchor ="center");
txtPwd = tk.Entry(f2);
txtPwd.place(x = 120, y = 50, width=145);
lblHide= tk.Label(f2, text = "Red Oculta: ", font =("verdana", 12));
lblHide.place(x = 66, y = 90, anchor ="center");
cbxShow = ttk.Combobox(f2,state="readonly",values=["No","Si"]);
cbxShow.current(0)
cbxShow.place(x = 120, y = 78);
btnGenerar = tk.Button(f2, text ="Generar QR", command = lambda: self.genera_code(f, txtSSID.get(), cbxSeg.get(), txtPwd.get(), cbxShow.get()));
btnGenerar.place(x = 75, y = 115);
btnGenerar.config(width=20, height=1);
ventana.mainloop();
if __name__ == '__main__':
objView = view();
objView.ViewGenerateQR();