Python 中的 QR 码2025年1月12日 | 阅读 19 分钟 二维码是一种条形码,易于数字设备读取,并以像素串的形式承载数据,这些像素以方形网格排列。由于许多智能手机都内置了二维码扫描仪,因此二维码常用于营销和推广活动。它们被广泛用于跟踪供应链中产品的相关数据。在当前监控新冠病毒暴露和阻止病毒传播的倡议中,它们被证明是必不可少的。 1994年,日本丰田子公司Denso Wave公司创建了第一项二维码技术。当时,他们需要一个更精确的系统来跟踪汽车和零部件的生产过程。为此,他们开发了一种能够读取日语汉字、假名和字母数字字符的特殊条形码。 传统条形码只能从上到下读取。因此,它们只能存储有限的数据,通常是字母数字格式。然而,二维码有两种读取方式:从上到下和从右到左。因此,它可以存储更多信息。二维码的设计团队旨在使其易于读取,以便工作人员不必浪费时间调整到正确的角度。他们还希望它具有独特的外观,使其脱颖而出。因此,他们最终选择了经久不衰的方形设计。 Denso Wave 公司宣布将放弃行使其专利权,使二维码免费可用。因此,任何人都可以创建和使用二维码。尽管这一概念花了一些时间才被接受,但第一批支持二维码的手机于2002年在日本推出。智能手机的普及促使使用二维码的企业数量不断增加。 传统上,产品包装上或宣传其优势的广告中可用的空间量限制了可以传输的关于商品或服务的信息量。如果客户想要更多关于产品的信息,例如其可用性、价格或功能,他们需要找到销售人员或获取额外的文件。 条形码经常出现在产品包装的背面,并使用不同长度的平行线组合来传输数据。这些代码可以通过配备光学扫描仪的设备读取。美国铁路公司在20世纪60年代首次使用条形码来跟踪货物和设备,彻底改变了企业处理库存和价格的方式。1974年,二维传统条形码在美国零售商店中得到了广泛应用。 如今,从集装箱到医院腕带和员工身份证,各种物品上都可以看到条形码。 静态二维码(如上图所示)经常用于分发公开信息。它们经常出现在报纸和杂志的广告中,以及海报和广告牌上。代码的创建者可以跟踪其代码被扫描的频率以及代码中包含的行动号召是否被遵循。动态二维码(也称为唯一二维码)具有更多功能。它们可以随时编辑,甚至可以定制以销售给特定个人。这些代码包含更多元数据以帮助跟踪。 与商店的条形码类似,二维码的功能也类似。每个二维码都由代表各种数据的黑方块和点组成。当条形码被扫描时,其独特的设计会转换为人类可读的数据。这个过程瞬间完成。 虽然现在大多数人使用智能手机扫描二维码,但用户必须有一个二维码阅读器或扫描仪才能获取信息。如果您的手机缺少此功能,有许多免费的二维码扫描应用程序,如NeoReader和QuickMark Barcode Scanner。动态二维码的一个重要优势是能够收集扫描指标。用户个人信息无法访问,但您可以查看每次扫描的日期、地点和使用的扫描设备。作为营销人员,我们深知这些数据对于衡量营销活动成功与否的重要性。 代码在主函数中,用户会看到一个菜单,其中提供了多种选项供用户选择。在菜单中呈现给用户的各种选项包括:输入将用于生成二维码的文本数据、输入将保存已生成二维码的文件名、生成带有输入数据并存储在指定文件名的二维码、输入需要读取的二维码文件名、从指定的二维码文件中读取数据、打印从二维码文件中读取的数据,以及最后一个选项是停止打印此菜单并退出代码执行。根据用户选择的选项类型,会通过在主函数中提前创建的对象来调用特定类的相应函数。如果用户调用的函数需要用户输入,它会要求用户提供适当的输入,然后对用户提供的输入执行各种必要的操作。 代码输出 Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 1 Enter the text from which you want to generate the QR code: Save this data in a QR code file To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 2 Enter the name of the file in which the generated QR code needs to be stored. The file needs to be in .png format. qrcodefile1.png To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 3 QR code generated successfully and saved in qrcodefile1.png file. To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 4 Enter the name of the file in which the QR code is saved. The file should be a .png file. qrcodefile1.png To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 5 QR code in the file named qrcodefile1.png read successfully. To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 6 The data which is read from the QR code file name [qrcodefile1.png] is [Save this data in a QR code file] To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 1 Enter the text from which you want to generate the QR code: Data with speci@l ch@r$ To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 2 Enter the name of the file in which the generated QR code needs to be stored. The file needs to be in .png format. qrfilewithspeicalchars.png To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 3 QR code generated successfully and saved in qrfilewithspeicalchars.png file. To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 4 Enter the name of the file in which the QR code is saved. The file should be a .png file. qrfilewithspeicalchars.png To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 5 QR code in the file named qrfilewithspeicalchars.png read successfully. To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 6 The data which is read from the QR code file name [qrfilewithspeicalchars.png] is [Data with speci@l ch@r$] To proceed with the printing of the menu which was getting displayed enter [Y] else [N] y Do select any of these options: To enter the text data from which the QR code will be generated. To enter the name of the file in which the genrated QR code will be saved. To generate a QR with the entered data which will be stored in the specified filename. To enter the name of the QR code file which needs to be read. To read the data from the specified QR code file. To print the data which has been read from the QR code file. To exit from the code execution. 7 在上面编写的代码中,主函数会呈现一个菜单,其中提供了多种选项供用户选择。在菜单中呈现给用户的各种选项包括:输入将用于生成二维码的文本数据、输入将保存已生成二维码的文件名、生成带有输入数据并存储在指定文件名的二维码、输入需要读取的二维码文件名、从指定的二维码文件中读取数据、打印从二维码文件中读取的数据,以及最后一个选项是停止打印此菜单并退出代码执行。根据用户选择的选项类型,会通过在主函数中提前创建的对象来调用特定类的相应函数。如果用户调用的函数需要用户输入,它会要求用户提供适当的输入,然后对用户提供的输入执行各种必要的操作。 二维码的优点
二维码的缺点
所以,在这篇文章中,我们了解了如何使用 Python 读取和创建二维码。 |
我们请求您订阅我们的新闻通讯以获取最新更新。