LUIDIBLU / tech blog
PT EN
PT EN

How to generate a QR code with Python

13 posts · 8,990 words · 46 min of reading · since 2016

0% read

How to generate a QR code with Python

A small experiment to generate a QR code using Python and the qrcode library.

TL;DR Too lazy to read? Click here.

QR codes spark a lot of interest, but also raise questions among users.

So I decided to put together a short tutorial on how to create/generate one of these codes.

(We’ll use the qrcode and OpenCV libraries.)

Dependencies:

bashpip3 install pillow qrcode

Now we can generate our QR code!

pythonimport qrcode

# Exemplo de data
data = "https://www.linkedin.com/in/diegopisani/"

# Nomeamos o arquivo 
filename = 'qrcode.png'

# Geramos o QR Code
img = qrcode.make(data)

# Salvamos a img num file
img.save(filename)

This code will generate a QR code pointing to LinkedIn (in this case, my profile).

And that’s the tutorial o/

Visitor dossier

Read only in your browser. The edge answers and keeps no log. Nothing is stored or sent to third parties.

Shortcuts

/⌘K
search and commands
?
this table
p
visitor dossier
t
light / dark theme
.
12-column grid
jk
next / previous post
enter
open the focused post
g hg pg tg sg r
go to home, posts, tags, about, rss
esc
close dialogs