Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate QR Code with python

Shulou Source: shulou.com Published: 2022-06-01 04:59:33 09月28日 Update

Editor to share with you how to use python to generate QR code, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Generate a QR code

QR code is also called 2D barcode. The common QR code is the full name Quick Response of QR Code,QR, which is a very popular coding method on mobile devices in recent years, and it is very easy to generate a QR code. In Python, we can generate a QR code through the MyQR module, while we only need 2 lines of code to generate a QR code. We first install the MyQR module. Here we choose the domestic source to download:

Pip install qrcode

After the installation is complete, we can start writing code:

Import qrcodetext = input (enter text or URL:) # set URL must add http://img = qrcode.make (text) img.save () # Save the picture to the local directory, you can set the path img.show ()

After we execute the code, we will generate a QR code under the project. Of course, we can also enrich the QR code:

Let's install the MyQR module first

Pip install myqrdef gakki_code (): version, level, qr_name = myqr.run (words= https://520mg.com/it/#/main/2, # can be a string or URL (preceded by http (s): / /) version=1, # set fault tolerance to the highest level='H', # control error correction level, with the range of L, M, Q, H. Increase the picture=gakki.gif from left to right, # combine the QR code and the picture into colorized=True, # the color QR code contrast=1.0, # to adjust the contrast of the picture, 1. 0 represents the original picture, a smaller value indicates lower contrast, and vice versa. The default is 1.0 brightness=1.0. # is used to adjust the brightness of the picture. The other usage and values are the same as the above save_name=gakki_code.gif. # saves the name of the file. The format can be jpg,png,bmp,gif save_dir=os.getcwd () # control location) gakki_code ()

In addition, MyQR also supports dynamic pictures.

The above is all the contents of the article "how to generate QR codes with python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: 2D QR code generation picture code module article content contrast control adjustment original highest for several years not much 2D barcode brightness position full name dynamic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Shulou Technology Docker Linux