LARRUZ builds a QR code generator in Python using Tkinter, with ChatGPT writing most of the code. The tutorial shows two debugging cycles: fixing Tkinter's incompatibility with the QR library's image format, then fixing a save function error. By the end, the app generates and saves QR codes for any website URL.
Questions this video answers
LARRUZ
January 20, 2023
Tkinter (referred to as Kinter/Kinto in the transcript)
"PhotoImage object has no attribute save"
That the QR code library returns a Pillow image which is not directly supported by Tkinter (needed conversion to a Tk-compatible image).
Chapters
Today I'll show you how to create a QR code generator for website links. We will do this using Python and the Kintor library. With the help of Chat GPT, the app will be able to generate the QR code given a link and will also store the image. I will also show you how to fix code errors using ChatGPT and what prompt to give to get better code from ChatGPT. So let's get started. Okay, so we prompt you, ChatGPT to use Python and Kinter to create a QR code generator for website links. We also ask it to show the QR code in the Kinto UI and also create and store a PNG file with the QR code, wait for it to finish the code generation. Then we will go ahead and copy the code and paste it in a Visual Code Studio file to run it in Python virtual environment. In the Visual Code Studio, I have created an empty file called QR Code Generator. So here I am simply pasting the code from the ChatGPT website and we can run this file using a Python Wisher environment. Once we run the file, you will see that it generates this small UI in Kinter. So it's asking us to enter a web link and then there is a button to generate the QR code. So let's try to generate it for google.com so in this case, when we click the generate code, it actually threw an error. So let's see how we can use ChatGPT to actually help us resolve this error. Simply copy the error message and paste it in the Chat GPT session that we are already running. The Great thing is ChatGPT not only identifies the error, but it actually also gives us a potential fix. So in this case it's saying that the QR code library returns a pillar image which is not supported by the Kinter library. Now we simply have to wait for it to generate the corrected code. In this case, it's simply generating the code for the generate QR function. So it's not replicating the whole code, but simply fixing that one function. Once the code is generated, we can go ahead and copy it and replace this function in our Visual Code studio. Okay, now we can run our updated code. So let's execute the file and we see that it generated the UI. So let's try to access google.com and generate QR code for that. Now you see that we are able to actually generate the QR code, but you will notice that it throws an error. It says that photo image object has no attribute save. So Even though it's able to generate the QR code, one of the requirement was to save it, right? But based on this error, it's not able to actually save the file. So again, we'll repeat the same process, copy the error message directly into the ChatGPT session and wait for it to come up with a fix and update the code. Now all we have to do is wait to finish the code generation. Then we will again copy it into Visual Code Studio, update our the QR and generator underscore QR function and simply run it again. With this process you can see that not only you can generate the code with Visual Code Studio. Sorry with the ChatGPT, but you can also ask it to fix errors, right? So let's say in this case it didn't throw an error. We are able to generate the qr code for google.com and also save it. We can also do that for YouTube. Com, you can try it for any website that you like and it will be able to generate the code and save the corresponding QR code as well. Hope you like this video. Please consider subscribing Happy Coding.