-1

I am learning from a tutorial online about how to generate QR Codes. I have started to create the frontend which is the application window with an input field and text label. I am now onto the backend which is the code for the 'Generate' button which allows the user to generate the QR Code with the inputted URL to assign the inputted URL with the QR Code.

I have previously tried to attempt to open the image of the QR Code in the window body area of the application and my code keeps on invoking the following error: AttributeError: type object 'Image' has no attribute 'open'. I currently am expecting it to open the Image in my application window so that I can scan it to ensure the QR Code redirects me to the website I have assigned it to but it instead causes the program to invoke the above error.

Python Code as it currently stands:

import qrcode
from PIL import Image
from tkinter import *

root = Tk()
root.geometry('500x500')
root.title('QR Code Generator Application')
root.resizable(0,0)

Label(root, text='QR Code Generator Application', font='Helvetica 18 bold').place(x=65, y=20)
Label(root, text='Enter anything into the input field: ', font='Helvetica 12').place(x=20, y=90)
Entry(root, width=25).place(x=250, y=93)

def button():
    qr_code= qrcode.QRCode(version=2, box_size=10, border=4)

    img = qr_code.make_image(fill='Black', back_color='Red')
    img.save('QR_Code_1.png')
    Image.open('QR_Code_1.png')

Button(root, text='Generate', font='Helvetica 15 bold', bg='Green', command=button).place(x=183, y=140)
root.mainloop()

If there is any way anyone could possibly help out a fellow beginner programmer, I'd be glad to consider any suggestions about the above code and how to solve the problem which I am currently having.

Thank you :)

1 Answer 1

0

The answer lays in here from tkinter import *. Seems like tkinter package has Image class, and because you're importing everything from it - you're importing that class that does not have open method. Be careful with what you're importing and try to avoid importing everything like this: from tkinter import Tk, Label, Entry, Button. That should solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.