QR Code'u ekrana yansıtma hatası

import tkinter as tk
from PIL import ImageTk, Image
import qrcode
import os

def qrCreate():
    input_data = urlName.get()
    qr = qrcode.QRCode(
        version=1,
        box_size=11,
        border=5)
    qr.add_data(input_data)
    qr.make(fit=True)
    img = qr.make_image(fill='black', back_color='white')
    img.save(f'{qrName.get()}.png')
    lbl_pngLocation = tk.Label(win, text=f"The location where the {qrName.get()}.png file is saved : {os.getcwd()}")
    lbl_pngLocation.place(x=3, y=300)
    img_path = f"{qrName.get()}.png"

    qrCode = Image.open(img_path)
    qrCode_resize = qrCode.resize((150,150))
    qrCode_resize = ImageTk.PhotoImage(qrCode_resize)

    lbl_qrCode = tk.Label(win, image=qrCode_resize)
    lbl_qrCode.place(x=230, y=350)


win = tk.Tk()
win.title(" QR Code Create ")
win.geometry("600x571")

urlName = tk.StringVar()
qrName = tk.StringVar()

lbl_qrName = tk.Label(win, text=" QR Name : ")
lbl_url = tk.Label(win, text=" URL : ")

lbl_url.place(x=200, y=97)
lbl_qrName.place(x=173, y=147)

ent_url = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=urlName)
ent_url.place(x=250, y=100)

ent_qrName = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=qrName)
ent_qrName.place(x=250, y=150)

btn_create = tk.Button(win, text=" CREATE ", command=qrCreate)
btn_create.place(x=275, y=210)


win.mainloop()

Yukarıda verdiğim QR Code Oluşturucu kodları oluşturulan QR COCE yi ekrana yansıtmıyor.
Çözümü nedir ?

import tkinter as tk
from PIL import ImageTk, Image
import qrcode
import os

def qrCreate():
    global lbl_qrcode
    input_data = urlName.get()
    qr = qrcode.QRCode(
        version=1,
        box_size=11,
        border=5)
    qr.add_data(input_data)
    qr.make(fit=True)
    img = qr.make_image(fill='black', back_color='white')
    img.save(f'{qrName.get()}.png')
    lbl_pngLocation = tk.Label(win, text=f"The location where the {qrName.get()}.png file is saved : {os.getcwd()}")
    lbl_pngLocation.place(x=3, y=300)
    img_path = f"{os.getcwd().replace(os.sep, os.altsep)}/{qrName.get()}.png"


    qrCode = Image.open(img_path)
    qrCode = qrCode.resize((150, 150))
    qrCode = ImageTk.PhotoImage(qrCode)

    lbl_qrCode = tk.Label(win, image=qrCode)
    lbl_qrCode.image= qrCode
    lbl_qrCode.place(x=230, y=500)



win = tk.Tk()
win.title(" QR Code Create ")
win.geometry("600x571")

urlName = tk.StringVar()
qrName = tk.StringVar()

lbl_qrName = tk.Label(win, text=" QR Name : ")
lbl_url = tk.Label(win, text=" URL : ")

lbl_url.place(x=200, y=97)
lbl_qrName.place(x=173, y=147)

ent_url = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=urlName)
ent_url.place(x=250, y=100)

ent_qrName = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=qrName)
ent_qrName.place(x=250, y=150)

btn_create = tk.Button(win, text=" CREATE ", command=qrCreate)
btn_create.place(x=275, y=210)

win.mainloop()

biraz garip oldu ama resim ekranda oluor gerekli yerleri ayarlarsın

1 Beğeni
import tkinter as tk
from PIL import ImageTk, Image
import qrcode
import os

def qrCreate():
    
    input_data = urlName.get()
    qr = qrcode.QRCode(
        version=1,
        box_size=11,
        border=5)
    qr.add_data(input_data)
    qr.make(fit=True)
    img = qr.make_image(fill='black', back_color='white')
    img.save(f'{qrName.get()}.png')
    lbl_pngLocation = tk.Label(win, text=f"The location where the {qrName.get()}.png file is saved : {os.getcwd()}")
    lbl_pngLocation.place(x=3, y=300)
    img_path = f"{os.getcwd()}/{qrName.get()}.png"
    print(img_path)
    img_path = img_path.replace("\\", '/')
    print(img_path)

    qrCode = Image.open(img_path)
    qrCode = qrCode.resize((150, 150))
    qrCode = ImageTk.PhotoImage(qrCode)

    lbl_qrCode = tk.Label(win, image=qrCode)
    lbl_qrCode.image= qrCode
    lbl_qrCode.place(x=230, y=350)



win = tk.Tk()
win.title(" QR Code Create ")
win.geometry("600x571")

urlName = tk.StringVar()
qrName = tk.StringVar()

lbl_qrName = tk.Label(win, text=" QR Name : ")
lbl_url = tk.Label(win, text=" URL : ")

lbl_url.place(x=200, y=97)
lbl_qrName.place(x=173, y=147)

ent_url = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=urlName)
ent_url.place(x=250, y=100)

ent_qrName = tk.Entry(win, bg="white", fg="black", bd=0, justify="left", relief="raised", textvariable=qrName)
ent_qrName.place(x=250, y=150)

btn_create = tk.Button(win, text=" CREATE ", command=qrCreate)
btn_create.place(x=275, y=210)

win.mainloop()

bir önceki gönderimimde çılgın şeyler yazmıstım os.sep / os.altsep gibi…
onları düzelttim. printler ile resim yolunun nasıl olduğunu görmek için eklemiştim. “” ları değiştirmesem kaçış dizileri ile çakışacaktı.

1 Beğeni

Evet, bende ne anlama geldiğini anlamaya çalışıyordum onların. Teşekkürler.