
pip install pyqrcode
To save the image in .png format, we will install pypng
pip install pypng
my_qr = pyqrcode.create('plus2net.com')
my_qr = my_qr.xbm(scale=10)
my_img=tk.BitmapImage(data=my_qr)
We can use my_img inside a label to display the image ( QR code ) by using config() method. Here we are only displaying the QR code and not storing the image in local system.
l1.config(image=my_img)
my_qr.svg('G:\\My Drive\\testing\\my_qr.svg', scale=8)
my_qr.png('G:\\My Drive\\testing\\my_qr1.png', scale=6,
module_color=[0, 0, 0, 128], background=[0xff, 0xcc, 0xcc])
Full code with saving option is here.
import pyqrcode
from pyqrcode import create
import tkinter as tk
from tkinter import *
import png # pip install pypng ## to save in png format
my_w = tk.Tk()
my_w.geometry("410x400") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
e1=tk.Entry(my_w,font=22,bg='yellow',width=15)
e1.grid(row=0,column=0,padx=10,pady=10)
b1=tk.Button(my_w,font=22,text='Generate QR code',
command=lambda:my_generate())
b1.grid(row=0,column=1,padx=5,pady=10)
l1=tk.Label(my_w,text='QR to display here')
l1.grid(row=1,column=0,columnspan=2)
def my_generate():
global my_img
my_qr = pyqrcode.create(e1.get())
#my_qr.svg('G:\\My Drive\\testing\\my_qr.svg', scale=8)#save svg
my_qr.png('G:\\My Drive\\testing\\my_qr1.png', scale=6,
module_color=[0, 0, 0, 128], background=[0xff, 0xcc, 0xcc])
my_qr.show() # display qr code image in console
my_qr = my_qr.xbm(scale=10)
my_img=tk.BitmapImage(data=my_qr)
l1.config(image=my_img) # Show the qr code in Label
my_w.mainloop() # Keep the window open

pip install Pillow
Change your path based on local system.
import pyqrcode
from PIL import Image
#url = pyqrcode.QRCode('https://www.plus2net.com',error = 'H')
url = pyqrcode.QRCode('welcome to plus2net',error = 'H')
url.png('D:\\my_qr_code.png',scale=10)
im = Image.open('D:\\my_qr_code.png')
im = im.convert("RGBA")
logo = Image.open("D:\\p2n-logo\\top2.jpg") # path to logo file
box = (100,165,280,200) # dimension for the logo to fix
im.crop(box)
region = logo
region = region.resize((box[2] - box[0], box[3] - box[1]))
im.paste(region,box)
im.show()
im.save("D:\\my_qr_code.png","PNG") # change your path

import pyqrcode
from pyqrcode import create
import tkinter as tk
import png # pip install pypng ## to save in png format
from PIL import Image
my_w = tk.Tk()
my_w.geometry("410x400") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
e1=tk.Entry(my_w,font=22,bg='yellow',width=15)
e1.grid(row=0,column=0,padx=10,pady=4)
b1=tk.Button(my_w,font=22,text='Generate QR code',
command=lambda:my_generate())
b1.grid(row=0,column=1,padx=5,pady=4)
l1=tk.Label(my_w,text='QR to display here')
l1.grid(row=1,column=0,columnspan=2)
path='G:\\My Drive\\testing\\my_qr2.png' # Update your path
def my_generate():
global my_img
my_qr = pyqrcode.QRCode(e1.get(),error = 'H')
my_qr.png(path, scale=10,module_color=[0, 0, 0, 128],
background=[0xff, 0xcc, 0xcc])
im = Image.open(path)
im = im.convert("RGBA")
logo = Image.open("D:\\p2n-logo\\top2.jpg")
box = (90,150,250,170) # dimension for the logo to fix
im.crop(box)
region = logo
region = region.resize((box[2] - box[0], box[3] - box[1]))
im.paste(region,box)
im.show() # display in console
im.save("path","PNG")
my_img = tk.PhotoImage(file = "path")
l1.config(image=my_img) # Show the qr code in Label
my_w.mainloop() # Keep the window open
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.