Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate blog address QR Code with Python third Party Library qrcode or MyQr

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to generate blog address QR code with Python third-party library qrcode or MyQr". In daily operation, I believe that many people have doubts about how to use Python third-party library qrcode or MyQr to generate blog address QR code. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the question of "how to use Python third-party library qrcode or MyQr to generate blog address QR code"! Next, please follow the editor to study!

Catalogue

Preparation in advance

Qrcode

MyQR

Install third-party libraries

Code

Running effect

Prepare qrcode in advance

Download address:

Qrcode PyPI

QR Code image generator

Https://pypi.org/project/qrcode/

Introduction to use:

Import qrcodeqr = 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

Download address:

MyQR PyPI

Https://pypi.org/project/MyQR/

Introduction to use:

From MyQR import myqrmyqr.run (words = 'https://blog.csdn.net/boysoft2002/article/details/120257133', save_name =' qrcode.jpg') # generate the QR code myqr.run with background image (words = 'https://blog.csdn.net/boysoft2002/article/details/120242318', picture = ringing background.jpgpicture, # support dynamic gif as background colorized = True, # True: color False: black and white save_name = 'qrcode.png') install third-party libraries

You can install either of the two as follows. If there are other dependent libraries, please install them as well:

D:\ > pip install qrcodeCollecting qrcode Downloading qrcode-7.3.tar.gz (43 kB) | ██ | 43 kB 191 kB/sCollecting 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. DoneSuccessfully installed colorama-0.4.4 qrcode-7.3D:\ > pip install MyQrCollecting 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/sRequirement 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... DoneSuccessfully installed MyQr-2.3.1 imageio-2.9.0 code

Take qrcode as an example, quickly generate the QR code of the blog (paste your own URL into the urls variable, the article title is not required).

Urls = 'Python the recursive improvement of the Fibonacci series, it takes only 4 seconds to calculate the 10 millionth item! Https://blog.csdn.net/boysoft2002/article/details/120257133Python really can't guess the time complexity of the recursive function if he doesn't try it himself. Time complexity and space complexity of https://blog.csdn.net/boysoft2002/article/details/120242318Python algorithm (instance analysis) text version of Sudoku game (non-GUI version) https://blog.csdn.net/boysoft2002/article/details/120202704'''import re,os,qrcodeimport tkinter as tkurl = re.findall (r 'https://.*[0-9]', urls) for I operated by https://blog.csdn.net/boysoft2002/article/details/120213715Python console U in enumerate (url): if u.find ('?')! =-1: url [I] = u [: u.find ('?)] # print (u) imgs,index = [] 0for 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 (205205 Image=png) cv.update () def on_close (): global imgs p = os.getcwd () if p [- 1]! ='\\': P + ='\\ 'for f in imgs: os.remove (pamphf) 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 (root,text=f'No:1: {imgs [0]}', command=nextqr,fg='red') btn.place ("WM_DELETE_WINDOW", on_close) root.mainloop () running effect

Click the button button to display the QR code one by one:

My environment: Windows7 + Python3.8.8

-- All done!

At this point, the study on "how to generate the QR code of blog address with Python third-party library qrcode or MyQr" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report