1+ import qrcode
2+ from PIL import Image
3+
4+ def generate_qr_code (data , version , error_correction , box_size , border ):
5+ # Create a QR Code instance with user-defined parameters
6+ qr = qrcode .QRCode (
7+ version = version , # controls the size of the QR Code
8+ error_correction = error_correction , # controls the error correction used for the QR Code
9+ box_size = box_size , # controls how many pixels each “box” of the QR code is
10+ border = border , # controls how many boxes thick the border should be
11+ )
12+
13+ # Add data to the QR Code
14+ qr .add_data (data )
15+ qr .make (fit = True )
16+
17+ # Create an image from the QR Code instance
18+ img = qr .make_image (fill_color = "black" , back_color = "white" )
19+
20+ # Show the image in a separate window
21+ img .show ()
22+
23+ def get_wifi_data ():
24+ ssid = input ("Enter the Wi-Fi SSID: " )
25+ password = input ("Enter the Wi-Fi password: " )
26+ encryption = input ("Enter the encryption type (WPA/WPA2/WEP/none): " )
27+ return f"WIFI:S:{ ssid } ;T:{ encryption } ;P:{ password } ;;"
28+
29+ def get_email_data ():
30+ email = input ("Enter the recipient's email address: " )
31+ subject = input ("Enter the email subject: " )
32+ body = input ("Enter the email body: " )
33+ return f"mailto:{ email } ?subject={ subject } &body={ body } "
34+
35+ def get_sms_data ():
36+ phone_number = input ("Enter the phone number: " )
37+ message = input ("Enter the message: " )
38+ return f"smsto:{ phone_number } :{ message } "
39+
40+ def get_contact_data ():
41+ name = input ("Enter the contact name: " )
42+ email = input ("Enter the contact email: " )
43+ phone = input ("Enter the contact phone number: " )
44+ return f"BEGIN:VCARD\n VERSION:3.0\n FN:{ name } \n EMAIL:{ email } \n TEL:{ phone } \n END:VCARD"
45+
46+ def get_location_data ():
47+ latitude = input ("Enter the latitude: " )
48+ longitude = input ("Enter the longitude: " )
49+ return f"https://www.google.com/maps?q={ latitude } ,{ longitude } "
50+
51+ if __name__ == "__main__" :
52+ print ("Select the type of QR code to generate:" )
53+ print ("1: URL" )
54+ print ("2: Plain Text" )
55+ print ("3: Wi-Fi Credentials" )
56+ print ("4: Email" )
57+ print ("5: SMS" )
58+ print ("6: Contact (vCard)" )
59+ print ("7: Location" )
60+
61+ choice = input ("Enter your choice (1-7): " )
62+
63+ if choice == '1' :
64+ data = input ("Enter the URL: " )
65+ elif choice == '2' :
66+ data = input ("Enter the plain text: " )
67+ elif choice == '3' :
68+ data = get_wifi_data ()
69+ elif choice == '4' :
70+ data = get_email_data ()
71+ elif choice == '5' :
72+ data = get_sms_data ()
73+ elif choice == '6' :
74+ data = get_contact_data ()
75+ elif choice == '7' :
76+ data = get_location_data ()
77+ else :
78+ print ("Invalid choice. Exiting." )
79+ exit ()
80+
81+ # Input QR code parameters
82+ version = int (input ("Enter the version {This indicates the size.} (1-40, default is 1): " ) or 1 )
83+
84+ # Error correction levels
85+ print ("Error correction levels:" )
86+ print ("1: ERROR_CORRECT_L (7% of codewords can be restored)" )
87+ print ("2: ERROR_CORRECT_M (15% of codewords can be restored)" )
88+ print ("3: ERROR_CORRECT_Q (25% of codewords can be restored)" )
89+ print ("4: ERROR_CORRECT_H (30% of codewords can be restored)" )
90+ error_correction_input = int (input ("Enter the error correction level (1-4, default is 1): " ) or 1 )
91+ error_correction = {
92+ 1 : qrcode .constants .ERROR_CORRECT_L ,
93+ 2 : qrcode .constants .ERROR_CORRECT_M ,
94+ 3 : qrcode .constants .ERROR_CORRECT_Q ,
95+ 4 : qrcode .constants .ERROR_CORRECT_H
96+ }.get (error_correction_input , qrcode .constants .ERROR_CORRECT_L )
97+
98+ box_size = int (input ("Enter the box size (default is 10): " ) or 10 )
99+ border = int (input ("Enter the border size (default is 4): " ) or 4 )
100+
101+ generate_qr_code (data , version , error_correction , box_size , border )
0 commit comments