难度:
pip install qrcode
点击显示代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import io import qrcode def text2qrcode(text): qr = qrcode.QRCode( # version=1, # error_correction=qrcode.constants.ERROR_CORRECT_L, # box_size=2, border=0, ) qr.add_data(text) f = io.StringIO() qr.print_ascii(out=f) f.seek(0) return f.read() if __name__ == '__main__': text = 'https://python-abc.xyz/basic/9604/' qc = text2qrcode(text) print(qc)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
█▀▀▀▀▀█ ▀ ▄███▄█▀▀ █▀▀▀▀▀█ █ ███ █ █▄█▀ ▀▄█ ▄ █▄ █ ███ █ █ ▀▀▀ █ ██ ▄ ▀▀▄█▀█ █ ▀▀▀ █ ▀▀▀▀▀▀▀ █▄▀▄▀ █ █ █ ▀ ▀▀▀▀▀▀▀ █ ██▀▀▀ ▄▄▀▀ ▄▄▄ ▀▄██▄███▀▀ ▄ ▀ ▄ ▄▀▀▀ █ ▄█▀▀█ ▀ █ ▀▄ ▄ █▄▄ ▄▀▄▀██▀▄ ▀ ▀ ██▄▄▄▄▀▀ ▄ ▀ ▄ ▄▀▀▄██▀▀ ▄█▄▀▀▄▄▄█▄█▀▀▄ ██ ▀██▀▀▄▀█▀▀▄▄▀▀█▄█ █▄█▄▀█ ▄ █ ▄▀▀▄▀▄▀▄█▀ █▀█ ▀▄▀ ▀▀▀ ▀▄ ▀ ▀ ▀▀▄ ▄ ▀▀▀▀▄ █▀▀▀█▄███ █▀▀▀▀▀█ ▄▀▄ ▄ ▄▀▄▀▀██ ▀ █▀▀▄▄ █ ███ █ █ ██▀ ▄▀▀██ █▀▀█▀▄██▄ █ ▀▀▀ █ ▀▀▀▄ █ █▀▀ ▄█▀▀██▀█ ▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀ ▀▀▀▀ ▀▀▀
可以看到是直接将二维码输出到终端了 上面看起来不怎么好看(可以扫码),其实在终端还是很好看的
=== 全文完 ===