Python第三方庫qrcode或MyQr生成博客地址二維碼
前期準(zhǔn)備
qrcode
下載地址:
qrcode · PyPI
QR Code image generator
https://pypi.org/project/qrcode/
使用簡介:
import qrcode qr = qrcode.QRCode( version=5, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('https://blog.csdn.net/boysoft2002/article/details/120213715') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white")
MyQR
下載地址:
MyQR · PyPI
https://pypi.org/project/MyQR/
使用簡介:
from MyQR import myqr myqr.run(words = 'https://blog.csdn.net/boysoft2002/article/details/120257133', save_name = 'qrcode.jpg' ) #生成帶背景圖片的二維碼 myqr.run(words = 'https://blog.csdn.net/boysoft2002/article/details/120242318', picture = r'background.jpg', #支持動(dòng)態(tài)gif作背景 colorized = True, # True:彩色,F(xiàn)alse:黑白 save_name = 'qrcode.png' )
安裝第三方庫
如下二選一安裝都可以,若存在其它依賴庫請(qǐng)一并安裝:
D:\>pip install qrcode Collecting qrcode Downloading qrcode-7.3.tar.gz (43 kB) |████████████████████████████████| 43 kB 191 kB/s Collecting colorama Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB) Using legacy 'setup.py install' for qrcode, since package 'wheel' is not installed. Installing collected packages: colorama, qrcode Running setup.py install for qrcode ... done Successfully installed colorama-0.4.4 qrcode-7.3 D:\>pip install MyQr Collecting MyQr Downloading MyQR-2.3.1.zip (16 kB) Collecting imageio>=1.5 Downloading imageio-2.9.0-py3-none-any.whl (3.3 MB) |████████████████████████████████| 3.3 MB 3.2 MB/s Requirement already satisfied: numpy>=1.11.1 in d:\python\lib\site-packages (from MyQr) (1.20.2) Requirement already satisfied: Pillow>=3.3.1 in d:\python\lib\site-packages (from MyQr) (8.2.0) Using legacy 'setup.py install' for MyQr, since package 'wheel' is not installed. Installing collected packages: imageio, MyQr Running setup.py install for MyQr ... done Successfully installed MyQr-2.3.1 imageio-2.9.0
代碼
以qrcode為例,快速生成博客的二維碼(粘貼自己的網(wǎng)址到urls變量中,文章標(biāo)題非必須項(xiàng))。
urls = ''' Python 斐波那契數(shù)列遞歸的改進(jìn),算第1000萬項(xiàng)只要4秒鐘! https://blog.csdn.net/boysoft2002/article/details/120257133 Python 不自己試試,還真猜不出遞歸函數(shù)的時(shí)間復(fù)雜度! https://blog.csdn.net/boysoft2002/article/details/120242318 Python 算法的時(shí)間復(fù)雜度和空間復(fù)雜度 (實(shí)例解析) https://blog.csdn.net/boysoft2002/article/details/120213715 Python 控制臺(tái)操作的文字版“數(shù)獨(dú)”游戲(非GUI版本) https://blog.csdn.net/boysoft2002/article/details/120202704 ''' import re,os,qrcode import tkinter as tk url = re.findall(r'https://.*[0-9]', urls) for i,u in enumerate(url): if u.find('?')!=-1: url[i] = u[:u.find('?')] #print(u) imgs,index = [],0 for u in url: img = qrcode.make(u) id = u[::-1] id = id[:id.find('/')][::-1] imgs.append('qrcode'+id+'.png') with open(imgs[-1],'wb') as f: img.save(f) def nextqr(): global imgs,index,png,qrc index += 1 if index==len(imgs):index = 0 btn['text']=f'No:{index+1}: {imgs[index]}' png = tk.PhotoImage(file=imgs[index]) qrc = cv.create_image(205,205,image=png) cv.update() def on_close(): global imgs p = os.getcwd() if p[-1]!='\\': p += '\\' for f in imgs: os.remove(p+f) root.destroy() root = tk.Tk() root.geometry('600x520') root.title('Qrcode') cv = tk.Canvas(root, width=410, height=410) cv.pack() png = tk.PhotoImage(file=imgs[0]) qrc = cv.create_image(205,205,image=png) btn = tk.Button(root,text=f'No:1: {imgs[0]}',command=nextqr,fg='red') btn.place(x=220,y=450) root.protocol("WM_DELETE_WINDOW", on_close) root.mainloop()
運(yùn)行效果
點(diǎn)擊 button 按鈕逐個(gè)展示二維碼:
我的使用環(huán)境:Windows7 + Python3.8.8
--All done!
以上就是Python第三方庫qrcode或MyQr生成博客地址二維碼的詳細(xì)內(nèi)容,更多關(guān)于Python第三方庫生成博客地址二維碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python?SQLAlchemy庫的實(shí)現(xiàn)示例
SQLAlchemy庫是一個(gè)強(qiáng)大的工具,為開發(fā)人員提供了便捷的方式來處理與數(shù)據(jù)庫的交互,本文主要介紹了Python?SQLAlchemy庫的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-06-06Python編程實(shí)現(xiàn)tail-n查看日志文件的方法
這篇文章主要介紹了Python編程實(shí)現(xiàn)tail-n查看日志文件的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07Java byte數(shù)組操縱方式代碼實(shí)例解析
這篇文章主要介紹了Java byte數(shù)組操縱方式代碼實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07numpy 對(duì)矩陣中Nan的處理:采用平均值的方法
今天小編就為大家分享一篇numpy 對(duì)矩陣中Nan的處理:采用平均值的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10Python實(shí)現(xiàn)層次分析法及自調(diào)節(jié)層次分析法的示例
這篇文章主要介紹了Python實(shí)現(xiàn)層次分析法及自調(diào)節(jié)層次分析法的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04Django點(diǎn)贊的實(shí)現(xiàn)示例
本文主要介紹了Django點(diǎn)贊的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03