QR codes are everywhere more and more businesses are using them to link to user manuals for products, videos on how to use products and direct them to their website etc.
二维码无处不在,越来越多的企业正在使用它们链接到产品的用户手册,有关如何使用产品的视频并将其定向到其网站等。
So what actually is a QR code?
那么,什么是QR码呢?
The quick response, or QR, Code is a two-dimensional version of the Barcode able to show a wide variety of information almost instantly with the scan of a mobile device.
快速响应或QR码是条形码的二维版本,能够在扫描移动设备时立即显示各种信息。
Most people have a QR Code scanning app installed on their phones, some even come as part of the phones OS. If not then a quick search in your App Store will no doubt give you results of many free QR code scanners to install.
大多数人的手机上都装有QR码扫描应用程序,有些甚至是手机操作系统的一部分。 否则,毫无疑问,在App Store中进行快速搜索将为您提供许多免费QR码扫描仪的安装结果。
So let’s say you scan a QR code which contains a web address (URL). When you scan it with your phone, you will be directed to the website that’s embedded inside the QR code.
假设您扫描了包含网址(URL)的QR码。 当您用手机扫描时,您将被定向到QR码中嵌入的网站。
People are even starting to use QR codes on their business cards to send people to their LinkedIn profiles or Twitter. The uses are endless.
人们甚至开始使用名片上的QR码将人们发送到其LinkedIn个人资料或Twitter。 用途是无止境的。
You can find many QR code generators online to create a QR code to then download, but wouldn’t it be nice to have your own personal app to do all of that and more offline?
您可以在线找到许多QR码生成器来创建一个QR码然后下载,但是拥有自己的个人应用程序来完成所有这些任务并脱机执行不是很好吗?
So let’s make one using Python!
因此,让我们使用Python做一个!
First we need to install a Python module called qrcode, to do this open up your Terminal and paste in the below command…
首先,我们需要安装一个名为qrcode的Python模块,为此打开您的终端并粘贴以下命令…
pip install qrcode
pip install qrcode
This will install qrcode for us to import into our Python script.
这将安装qrcode以便我们导入到我们的Python脚本中。
First we need to import qrcode
首先我们需要导入二维码
import qrcode
import qrcode
Then we can create a function to generate our QR code, I will explain the code in a minute.
然后我们可以创建一个函数来生成我们的QR码,我将在稍后解释。
def qr_code(): user_data = input(“\nPlease enter the data you want inside your QR Code:”) img = qrcode.make(user_data) img.save(‘QR Code.png’) img.show() print(‘\nQR Code Generated\n’)So to start the above code creates a variable named `user_data` and lets the user input data that they need inside the QR code. We then create a second variable `img` to place that `user_data` into. The `qrcode.make` then creates our QR code from our `user_data`, then we save `img` and show it on screen.
因此,要启动上述代码,将创建一个名为“ user_data”的变量,并允许用户在QR码内输入所需的数据。 然后,我们创建第二个变量`img`来放置`user_data`。 然后,`qrcode.make`根据`user_data`创建我们的QR码,然后保存`img`并将其显示在屏幕上。
It really is as simple as that!
它真的是那么简单!
In Action 行动中The full code is below:
完整的代码如下:
import qrcodedef qr_code(): user_data = input(“\nPlease enter the data you want inside your QR Code:”) img = qrcode.make(user_data) img.save(‘QR Code.png’) img.show() print(‘\nQR Code Generated\n’)qr_code()You could really jazz this app up by giving it a GUI (Graphical User Interface) by using Page (I did an article on how to do this here).
您可以通过使用Page为其提供一个GUI(图形用户界面)来真正使该应用爵士化(我在这里做了一篇有关如何执行此操作的文章)。
Go ahead and create as many QR codes as you like.
继续创建任意数量的QR码。
If you liked this article then be sure to take a look at some of my other articles here.
如果您喜欢这篇文章,那么一定要在这里看看我的其他一些文章。
Did you know that we have three publications and a YouTube channel? Find links to everything at plainenglish.io!
您知道我们有三个出版物和一个YouTube频道吗? 在plainenglish.io上找到所有内容的链接!
翻译自: https://medium.com/python-in-plain-english/create-a-qr-code-generator-using-python-31791cee8a
相关资源:python二维码生成器