QR code generator using python

QR Code generator using python

Hello coders we create this project with Python Tkinter, pyqrcode, pypng, pillow, Module

  •   In this project we create QR code generator program

Libraries used-

  >>Tkinter(for GUI)

  >>Pillow(for showing png)

  >>pyQrcode (for QR code )

  >>pypng (for creating QR png)

Step to create GUI-

  • Install Tkinter using pip install
  • Install Pillow using pip install
  • Import Tkinter
  • Create the main window
  • Import button png
  • Create entry and buttons

Algorithm-

  • Create generate and save_file function .
  • Using pip install pypng and pyqrcode.
  • Using pyqrcode generate the QRcode .
  • Using pypng save the created QRcode in png.
  • Using pillow module show the created QRcode png
  • Using filedialog save the created png
  • Create entry box for text or url.
  • Create button over png and add command to it.

Source Code:

#Importing Libraries--------------------------------------------------------------------------------------------------------

import pyqrcode  #also install pypng

from tkinter import *

import tkinter

from PIL import ImageTk,Image

from tkinter import messagebox

from tkinter.filedialog import asksaveasfilename as ask







#Function for generating QR code--------------------------------------------------------------------------------------------

def generateQR() :

    inputString = enterTextField.get()

    scale = 5    

    if len(inputString) :

        

        qrCode = pyqrcode.create(inputString)

        qrCode.png("qrcode.png",scale = scale)

        show_img = Image.open('qrcode.png')

        tst = ImageTk.PhotoImage(show_img)

        L = tkinter.Label(image=tst)

        L.image=tst

        L.place(x=110,y=70)

    

    else :

    

        messagebox.showerror("Error", "Text field is Empty")









#Function for saving QR code--------------------------------------------------------------------------------------------

def save_file():

    inputString = enterTextField.get()

    scale = 8

    if len(inputString) :

        qrCode = pyqrcode.create(inputString)

        path = ask(initialfile="Untitled.png",defaultextension='.png')



        qrCode.png(path,scale = scale)

    

        messagebox.showinfo('Success',"File generated Saved Successfily")

 

    else :

        messagebox.showerror("Error", "Text field is Empty")

 

 

#creating window------------------------------------------------------------------------------------------------------------

window = Tk()    

window.configure(background = 'light green')    

window.geometry("428x400") 

window.title("QR CODE GENERATOR")





#Entry box------------------------------------------------------------------------------------------------------------------   

enterTextField=Entry(window,font=("Time New Roman",16,"bold"),bd=1)

enterTextField.place(x=1,y=1,width=300,height=42)

enterTextField.insert(0,"Enter Text/URL")

def click(event):

    enterTextField.delete(0,END)

    enterTextField.insert(0,'')



enterTextField.bind('<FocusIn>',click)



#generate button------------------------------------------------------------------------------------------------------------

img = PhotoImage(file="generate.png") 

generateButton = Button(window,image=img,bg ="light green",bd=0,command = generateQR)

generateButton.place(x=300,y=1)



#save button----------------------------------------------------------------------------------------------------------------

saveimg = PhotoImage(file="save_btn.png") 

save_button = Button(window,image=saveimg,bg ="light green",bd=0,command = save_file)

save_button.place(x=160,y=300)



   

window.mainloop()


Output:

Write a comment