In this simple Python guide, we will be creating an application that generates and saves QR Codes. QR codes contain data for locations, identifiers, or trackers that point to a website or application.
Our Requirements
Before we get started, you will need to install the qrcode library for Python. A Quick Response code is a two-dimensional pictographic code used for its fast readability and comparatively large storage capacity. The code consists of black modules arranged in a square pattern on a white background. The information encoded can be made up of any kind of data (e.g., binary, alphanumeric, or Kanji symbols).
pip install qrcode
Let’s Get Started
Other than importing the QR Code library, there is nothing else to import. The following will generate the QR Code for the passed data and save it as an image in the working directory.
#!/usr/bin/python3 import qrcode def generate_qr(data): # File Name to save QR Code filename = "qrcode.png" # Generate QR Code with data img = qrcode.make(data) # Save the QR Code as an image img.save(filename) if __name__ == '__main__': # Call the `generate_qr` function and pass # the data that we want to have generated # as a QR Code. generate_qr("https://jmoorewv.com")
Example Output: