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


  • 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)




    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.title("QR CODE GENERATOR")

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

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


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

def click(event):




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

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

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


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

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

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





Write a comment