A PYTHON TKINTER APP TO MAKE QRCODES IN A FEW LINES COMPLETELY OFFLINE

This application makes the creation of qrcodes easier and offline, you can add any information in this qrcodes even links to open up websites

This application is so simple that it only has one function whose role is to get the information to store and the file to save as

python tkinter qrcode app offline

For this just pip install qrcode

And pip install Pillow

Pillow or pil is a python imaging library here we used it to resize our logo for the application

First import the needed libraries

Tkinter for the GUI

Pil to resize image

Qrcode to make our qrcode

#import tkinter for gui creation
from tkinter import *
# import pil to resize image
from PIL import Image,ImageTk
#import qrcode to create the qrcode
import qrcode
#import message box f rom tkinter to display messages
from tkinter import messagebox

Create the apps main window as app

Set the background color of the app

Set the window size of the app

Then add the title of the app

#create app main window name it as app
app=Tk()
#set app background_color to white
app.config(bg='white')
#set app size 
app.geometry('300x250')
#set app title
app.title('Qrcode creator')

Load our logo and resize it

Create a label to display the logo

Create label for infor to embed

#load image to be set as logo
image=Image.open('logo2.png')
#resize image and make it suitable in tkinter
r=image.resize((100,100))
img=ImageTk.PhotoImage(r)
#label to display logo
image=Label(image=img).pack()
#label to show user positon of entering link
lab1=Label(text='link/info to embbede ',bg='white',fg='black').pack()
#create a tkinter variable to store link
link=StringVar()
#create entry box were users enter link
entry=Entry(textvariable=link).pack()
#label for file name
lab1=Label(text='filename to save us',bg='white',fg='black').pack()

Create a tkinter variable to store link

Create entry where user can enter info or link to store

Create label for file name

Create tkinter variable for filename

Create another entry box for entering filename

Create a button that will call a function to save the qrcode

app.mainloop() keeps the app to run waiting for user inputs

#tkinter variable for filename
filename=StringVar()
#entry box for file name 
entry=Entry(textvariable=filename).pack()
#button to call the save function
Button1=Button(text='save Qrcode',command=save,bg='black',fg='white').pack()
#this is to run the app and wait for user  action
app.mainloop()

define function to save the info into a qrcode

get the filename from tkinter variable then add the format .png

because we are saving it as png image

get the link from tkinter link /info variable

create the code ,save it and display a message upon success of saving

def save():
    #get file name from tkinter variable
    file=filename.get()
    #saving to the format png show append png at end of filename
    file=file+'.png'
    #get link from tkinter variable
    info=link.get()
    #create the qrcode
    img = qrcode.make(info)
    #save the Qrcode
    img.save(file)
    #display message that file has been saved successfully
    messagebox.showinfo('info','Qrcode saved successfully\nin your current working dir0ectory')

fullcode of the python tkinter QRcode application

#import tkinter for gui creation
from tkinter import *
# import pil to resize image
from PIL import Image,ImageTk
#import qrcode to create the qrcode
import qrcode
#import message box f rom tkinter to display messages
from tkinter import messagebox
#function to save qrcode
def save():
    #get file name from tkinter variable
    file=filename.get()
    #saving to the format png show append png at end of filename
    file=file+'.png'
    #get link from tkinter variable
    info=link.get()
    #create the qrcode
    img = qrcode.make(info)
    #save the Qrcode
    img.save(file)
    #display message that file has been saved successfully
    messagebox.showinfo('info','Qrcode saved successfully\nin your current working directory')
#create app main window name it as app
app=Tk()
#set app background_color to white
app.config(bg='white')
#set app size 
app.geometry('300x250')
#set app title
app.title('Qrcode creator')
#load image to be set as logo
image=Image.open('logo2.png')
#resize image and make it suitable in tkinter
r=image.resize((100,100))
img=ImageTk.PhotoImage(r)
#label to display logo
image=Label(image=img).pack()
#label to show user positon of entering link
lab1=Label(text='link/info to embbede ',bg='white',fg='black').pack()
#create a tkinter variable to store link
link=StringVar()
#create entry box were users enter link
entry=Entry(textvariable=link).pack()
#label for file name
lab1=Label(text='filename to save us',bg='white',fg='black').pack()
#tkinter variable for filename
filename=StringVar()
#entry box for file name 
entry=Entry(textvariable=filename).pack()
#button to call the save function
Button1=Button(text='save Qrcode',command=save,bg='black',fg='white').pack()
#this is to run the app and wait for user  action
app.mainloop()

out put of the python tkinter qrcode maker

Leave a comment

Design a site like this with WordPress.com
Get started