python_使用qrcode生成二维码

1.功能

使用qrcode生成二维码

2.代码

#生成二维码:
import qrcode

#根据url生成二维码
def qrcodeWithUrl(url):
    img = qrcode.make(url)
    savePath = "1.png"
    img.save(savePath)

#根据输入的文字生成二维码
def qrcodeWithText(text):
    img = qrcode.make(text)
    savePath = "2.png"
    img.save(savePath)

#输入一句话
content = input("请输入一名话:")
if "http" in content:
    qrcodeWithUrl(content)
else:
    qrcodeWithText(content)

print("二维码已生成完毕,请查看!")

猜你喜欢

转载自www.cnblogs.com/doitjust/p/9275957.html