ساخت QR Code
برنامه ای بنویسید که یک url یا متن دریافت کند و آن را تبدیل به یک QR code کند و با پسوند png ذخیره کند.
برنامه ای بنویسید که یک url یا متن دریافت کند و آن را تبدیل به یک QR code کند و با پسوند png ذخیره کند.
import qrcode
import random
from colorama import Fore , Back , Style
from PIL import ImageColor
while True:
url = input(f"[To Exit 'exit']\n{Fore.LIGHTBLUE_EX}Enter URL or text: {Style.RESET_ALL}").strip()
if url == "exit":
exit()
cf = input(f"{Fore.GREEN}foreground color: {Style.RESET_ALL}").strip()
cb = input(f"{Fore.YELLOW}background color: {Style.RESET_ALL}").strip()
try:
ImageColor.getrgb(cf)
ImageColor.getrgb(cb)
except:
print(f"{Fore.RED}Invalid color!{Style.RESET_ALL}")
continue
if cf == cb:
print(f"{Fore.RED}Foreground color = Background color = Error{Style.RESET_ALL}")
continue
qr = qrcode.QRCode(version = 1 , box_size = 10 , border = 5)
qr.add_data(url)
qr.make(fit = True)
fn = random.randint(1000,100000)
img = qr.make_image(fill_color = cf , back_color = cb)
img.save(f"qrcode_{fn}.png")
print(f"{Fore.GREEN}qrcode{fn}.png saved.{Style.RESET_ALL}")
import qrcode
def create_qr_code(data, filename):
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill='black', back_color='white')
img.save(filename)
url = input("Enter URL or text: ")
create_qr_code(url, 'qrcode.png')
import qrcode
import random
from PIL import ImageColor
import customtkinter as ctk
from tkinter import messagebox
app = ctk.CTk()
app.geometry("460x320")
app.title("QRCode Creator")
app.resizable(False , False)
ctk.set_appearance_mode("Light")
frame = ctk.CTkFrame(app , corner_radius = 6 , border_color = 'white' , border_width = 4)
frame.pack(pady = 10)
frame.configure(fg_color = "#dadada")
l = ctk.CTkLabel(frame , text = "QRCode Creator" , width = 410 , text_color = "#161616" , font = ("ubuntu" , 24))
l.pack(pady = 12)
url_e = ctk.CTkEntry(frame , placeholder_text = "Enter URL or text" , font = ("ubuntu" , 21) , justify = "center" , width = 360 , height = 42)
url_e.pack(pady = 10)
cf_e = ctk.CTkEntry(frame , placeholder_text = "foreground color" , font = ("ubuntu" , 21) , justify = "center" , width = 360 , height = 42)
cf_e.pack(pady = 10)
cb_e = ctk.CTkEntry(frame , placeholder_text = "background color" , font = ("ubuntu" , 21) , justify = "center" , width = 360 , height = 42)
cb_e.pack(pady = 10)
def check_make():
url = url_e.get().strip()
cf = cf_e.get().strip()
cb = cb_e.get().strip()
try:
ImageColor.getrgb(cf)
ImageColor.getrgb(cb)
except:
messagebox.showerror("Error" , "Invalid color!")
if cf == cb:
messagebox.showerror("Error" , "Foreground color = Background color = Error")
else:
qr = qrcode.QRCode(version = 1 , box_size = 10 , border = 5)
qr.add_data(url)
qr.make(fit = True)
fn = random.randint(1000,100000)
img = qr.make_image(fill_color = cf , back_color = cb)
img.save(f"qrcode_{fn}.png")
messagebox.showinfo("QRCode Saved" , f"QRCode was made successfully by name 'qrcode{fn}.png'")
url_e.delete(0 , "end")
cf_e.delete(0 , "end")
cb_e.delete(0 , "end")
btn = ctk.CTkButton(frame , width = 370 , height = 45 , text = "Make QRCode" , font = ("ubuntu" , 24) , text_color = "#1D1D1D" , fg_color = "#bdbdbd", hover_color = "#d1d1d1" , command = check_make)
btn.pack(pady = 10)
app.mainloop()
import qrcode
import os
def click():
url = 'https://www.accuweather.com/en/ir/tehran/210841/weather-forecast/210841'
image = qrcode.make(url)
image.save("qrcode.png")
os.system('qrcode.png')
click()
این روش دوم هستش
کد رو داخل vs code وارد کردم ولی وقتی میخام اجرا کنم ارور میده کسی میتونه کمک کنه
import qrcode
import os
def click(text):
image = qrcode.make(text)
image.save("qrcode.png")
os.system("qrcode.png")
print(click(text=str(input("enter your text:"))))
روش اول
ماژول os برای ذخیره فایل بصورت png و ماژول qrcode برای ساخت کیوارکود.
import qrcode as qr
import os
data= input(f'Entger the message to be encoded :')
img=qr.make(data)
img.save('myqr.png')
os. system('myqr.png')
# pip install pyqrcode
import pyqrcode
def create_qrcode(url, file):
try:
qrcode = pyqrcode.create(url)
qrcode.svg(file, scale=6)
return True
except Exception as error:
return error
print(create_qrcode(input("Enter your link to convert to qrcode: "), "qrcode.png"))
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام