Python使用Segno生成艺术二维码报错:QRCode无to_artistic属性
问题解决:Segno QRCode对象无to_artistic属性
错误原因
你仅安装了qrcode-artistic依赖,但未在代码中显式导入该模块,导致Segno的QRCode对象未被注入to_artistic方法。
修正方案
方案1:导入qrcode_artistic启用对象方法
修改代码添加import qrcode_artistic,同时注意不要用背景图文件名作为目标文件名(避免覆盖原图片):
import segno import qrcode_artistic # 必须导入此模块才能启用to_artistic方法 qrcode = segno.make("Test QR Code Generate") qrcode.save('address.png', dark='darkred', light='lightblue', scale=10) # 目标文件不要与背景图同名,防止覆盖原背景 qrcode.to_artistic(background='my_image.png', target='artistic_qr.png', scale=8)
方案2:直接调用qrcode_artistic模块的函数
如果不想依赖模块对Segno的扩展,也可以直接调用模块提供的to_artistic函数:
import segno import qrcode_artistic qrcode = segno.make("Test QR Code Generate") qrcode.save('address.png', dark='darkred', light='lightblue', scale=10) qrcode_artistic.to_artistic(qrcode, background='my_image.png', target='artistic_qr.png', scale=8)
内容的提问来源于stack exchange,提问作者Arvin
相关产品推荐
相关产品推荐

