How can Python generate QR code images?

To generate a QR code image in Python, you can use the third-party library qrcode. Below is a simple example code:

import qrcode

# 生成二维码图片
data = "https://www.example.com"
img = qrcode.make(data)

# 保存二维码图片
img.save("qrcode.png")

In the example above, we imported the qrcode library and used the qrcode.make() function to generate a QR code image, then saved it as a png file using the img.save() function. You can adjust the data and file name according to your needs.

bannerAds