{"id":1126257,"date":"2025-01-08T19:59:23","date_gmt":"2025-01-08T11:59:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1126257.html"},"modified":"2025-01-08T19:59:27","modified_gmt":"2025-01-08T11:59:27","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e6%9d%a5%e7%bc%96%e5%86%99%e4%ba%8c%e7%bb%b4%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1126257.html","title":{"rendered":"\u5982\u4f55\u7528python\u6765\u7f16\u5199\u4e8c\u7ef4\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090634\/47d06d3f-25ed-48ad-9cde-fc83cb0b9ff7.webp\" alt=\"\u5982\u4f55\u7528python\u6765\u7f16\u5199\u4e8c\u7ef4\u7801\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u6765\u7f16\u5199\u4e8c\u7ef4\u7801<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u7f16\u5199\u4e8c\u7ef4\u7801\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u5b89\u88c5\u76f8\u5173\u5e93\u3001\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u5b9a\u5236\u4e8c\u7ef4\u7801\u3001\u4fdd\u5b58\u548c\u663e\u793a\u4e8c\u7ef4\u7801<\/strong>\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7Python\u751f\u6210\u548c\u81ea\u5b9a\u4e49\u4e8c\u7ef4\u7801\uff0c\u7740\u91cd\u8bb2\u89e3\u6bcf\u4e2a\u6b65\u9aa4\u7684\u5b9e\u9645\u64cd\u4f5c\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u76f8\u5173\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4e8c\u7ef4\u7801\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u76f8\u5173\u7684Python\u5e93\u3002\u6700\u5e38\u7528\u7684\u5e93\u662f<code>qrcode<\/code>\u548c<code>Pillow<\/code>\u3002<code>qrcode<\/code>\u7528\u4e8e\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u800c<code>Pillow<\/code>\u7528\u4e8e\u5904\u7406\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install qrcode[pil]<\/p>\n<p>pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u751f\u6210\u7b80\u5355\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u57fa\u672c\u6b65\u9aa4\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/strong><\/h2>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,  # \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u5927\u5c0f\uff0c\u53d6\u503c\u4e3a1~40\uff0c\u503c\u8d8a\u5927\u5c3a\u5bf8\u8d8a\u5927<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,  # \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u7ea0\u9519\u6c34\u5e73<\/p>\n<p>    box_size=10,  # \u63a7\u5236\u6bcf\u4e2a\u4e8c\u7ef4\u7801\u683c\u5b50\u7684\u50cf\u7d20\u6570<\/p>\n<p>    border=4,  # \u63a7\u5236\u4e8c\u7ef4\u7801\u8fb9\u6846\u7684\u683c\u5b50\u5bbd\u5ea6<\/p>\n<p>)<\/p>\n<h2><strong>\u5411\u4e8c\u7ef4\u7801\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>qr.add_data(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u751f\u6210\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a<code>QRCode<\/code>\u5bf9\u8c61\uff0c\u5e76\u6307\u5b9a\u4e86\u7248\u672c\u3001\u7ea0\u9519\u6c34\u5e73\u3001\u683c\u5b50\u5927\u5c0f\u548c\u8fb9\u6846\u5bbd\u5ea6\u7b49\u53c2\u6570\u3002\u7136\u540e\u4f7f\u7528<code>add_data<\/code>\u65b9\u6cd5\u5411\u4e8c\u7ef4\u7801\u5bf9\u8c61\u6dfb\u52a0\u6570\u636e\uff0c\u6700\u540e\u8c03\u7528<code>make_image<\/code>\u65b9\u6cd5\u751f\u6210\u56fe\u50cf\u5e76\u663e\u793a\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5b9a\u5236\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u751f\u6210\u7b80\u5355\u7684\u4e8c\u7ef4\u7801\uff0c<code>qrcode<\/code>\u5e93\u8fd8\u5141\u8bb8\u6211\u4eec\u5bf9\u4e8c\u7ef4\u7801\u8fdb\u884c\u5404\u79cd\u5b9a\u5236\uff0c\u4f8b\u5982\u66f4\u6539\u989c\u8272\u3001\u6dfb\u52a0Logo\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1. \u66f4\u6539\u4e8c\u7ef4\u7801\u989c\u8272<\/h4>\n<\/p>\n<p><p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e8c\u7ef4\u7801\u662f\u9ed1\u767d\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>make_image<\/code>\u65b9\u6cd5\u4e2d\u7684\u53c2\u6570\u6765\u66f4\u6539\u4e8c\u7ef4\u7801\u7684\u989c\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">img = qr.make_image(fill_color=&quot;blue&quot;, back_color=&quot;yellow&quot;)<\/p>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6dfb\u52a0Logo<\/h4>\n<\/p>\n<p><p>\u5728\u4e8c\u7ef4\u7801\u4e2d\u6dfb\u52a0Logo\u53ef\u4ee5\u589e\u52a0\u54c1\u724c\u7684\u8fa8\u8bc6\u5ea6\u3002\u9700\u8981\u7528\u5230<code>Pillow<\/code>\u5e93\u6765\u5904\u7406\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/strong><\/h2>\n<p>qr.add_data(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u751f\u6210\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u6253\u5f00Logo\u56fe\u50cf<\/strong><\/h2>\n<p>logo = Image.open(&#39;logo.png&#39;)<\/p>\n<h2><strong>\u8ba1\u7b97Logo\u7684\u5c3a\u5bf8<\/strong><\/h2>\n<p>box = (135, 135, 235, 235)  # \u6839\u636e\u4e8c\u7ef4\u7801\u7684\u5c3a\u5bf8\u8c03\u6574\u4f4d\u7f6e<\/p>\n<p>logo = logo.resize((box[2] - box[0], box[3] - box[1]), Image.ANTIALIAS)<\/p>\n<h2><strong>\u5c06Logo\u7c98\u8d34\u5230\u4e8c\u7ef4\u7801\u56fe\u50cf\u4e0a<\/strong><\/h2>\n<p>img.paste(logo, box)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf\uff0c\u7136\u540e\u6253\u5f00Logo\u56fe\u50cf\u5e76\u8c03\u6574\u5176\u5c3a\u5bf8\uff0c\u6700\u540e\u5c06Logo\u7c98\u8d34\u5230\u4e8c\u7ef4\u7801\u56fe\u50cf\u7684\u4e2d\u95f4\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4fdd\u5b58\u548c\u663e\u793a\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u4e8c\u7ef4\u7801\u540e\uff0c\u53ef\u4ee5\u5c06\u5176\u4fdd\u5b58\u4e3a\u6587\u4ef6\u6216\u76f4\u63a5\u663e\u793a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u4e8c\u7ef4\u7801<\/p>\n<p>img.save(&quot;qrcode.png&quot;)<\/p>\n<h2><strong>\u663e\u793a\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u4f7f\u7528<code>save<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u4e8c\u7ef4\u7801\u56fe\u50cf\u4fdd\u5b58\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528<code>show<\/code>\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u663e\u793a\u4e8c\u7ef4\u7801\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u751f\u6210\u5e26\u6709\u4e0d\u540c\u7ea0\u9519\u7ea7\u522b\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u6709\u56db\u4e2a\u4e0d\u540c\u7684\u7ea0\u9519\u7ea7\u522b\uff1aL\u3001M\u3001Q\u3001H\u3002\u7ea0\u9519\u7ea7\u522b\u8d8a\u9ad8\uff0c\u53ef\u4ee5\u6062\u590d\u7684\u635f\u574f\u6570\u636e\u8d8a\u591a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/strong><\/h2>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_H,  # \u6700\u9ad8\u7ea0\u9519\u7ea7\u522b<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<h2><strong>\u5411\u4e8c\u7ef4\u7801\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>qr.add_data(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u751f\u6210\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c06<code>error_correction<\/code>\u53c2\u6570\u8bbe\u7f6e\u4e3a<code>ERROR_CORRECT_H<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u4e8c\u7ef4\u7801\u53ef\u4ee5\u6062\u590d\u7ea630%\u7684\u635f\u574f\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6279\u91cf\u751f\u6210\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u6279\u91cf\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u4f8b\u5982\u4e3a\u6bcf\u4e2a\u7528\u6237\u751f\u6210\u552f\u4e00\u7684\u4e8c\u7ef4\u7801\u3002\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>data_list = [&#39;https:\/\/www.example1.com&#39;, &#39;https:\/\/www.example2.com&#39;, &#39;https:\/\/www.example3.com&#39;]<\/p>\n<p>for i, data in enumerate(data_list):<\/p>\n<p>    qr = qrcode.QRCode(<\/p>\n<p>        version=1,<\/p>\n<p>        error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>        box_size=10,<\/p>\n<p>        border=4,<\/p>\n<p>    )<\/p>\n<p>    qr.add_data(data)<\/p>\n<p>    qr.make(fit=True)<\/p>\n<p>    img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<p>    img.save(f&#39;qrcode_{i}.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u6570\u636e\u5217\u8868\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u6570\u636e\u751f\u6210\u4e00\u4e2a\u4e8c\u7ef4\u7801\u3002\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u5c06\u88ab\u4fdd\u5b58\u4e3a\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e2d\u5305\u542b\u5f53\u524d\u5faa\u73af\u7684\u7d22\u5f15\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u751f\u6210\u542b\u6709\u591a\u884c\u6587\u672c\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5728\u4e8c\u7ef4\u7801\u4e2d\u5b58\u50a8\u591a\u884c\u6587\u672c\u6570\u636e\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5c06\u591a\u884c\u6587\u672c\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>data = &quot;&quot;&quot;Line 1<\/p>\n<p>Line 2<\/p>\n<p>Line 3&quot;&quot;&quot;<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c06\u591a\u884c\u6587\u672c\u6570\u636e\u8d4b\u503c\u7ed9\u4e00\u4e2a\u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u6570\u636e\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u751f\u6210\u542b\u6709\u975e\u82f1\u6587\u5b57\u7b26\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u53ef\u4ee5\u5b58\u50a8\u4efb\u4f55\u7c7b\u578b\u7684\u6587\u672c\u6570\u636e\uff0c\u5305\u62ec\u975e\u82f1\u6587\u5b57\u7b26\u3002\u786e\u4fddPython\u4ee3\u7801\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f\u4e3aUTF-8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>data = &#39;\u3053\u3093\u306b\u3061\u306f\u3001\u4e16\u754c\uff01&#39;  # \u65e5\u6587\u5b57\u7b26<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c06\u5305\u542b\u65e5\u6587\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u6570\u636e\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u751f\u6210\u5e26\u6709\u6ce8\u91ca\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5728\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6ce8\u91ca\u3002\u53ef\u4ee5\u4f7f\u7528<code>Pillow<\/code>\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<p>import qrcode<\/p>\n<p>data = &#39;https:\/\/www.example.com&#39;<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6ce8\u91ca<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(img)<\/p>\n<p>font = ImageFont.load_default()<\/p>\n<p>text = &quot;Example QR Code&quot;<\/p>\n<p>textwidth, textheight = draw.textsize(text, font)<\/p>\n<p>width, height = img.size<\/p>\n<p>x = (width - textwidth) \/ 2<\/p>\n<p>y = height - textheight - 10<\/p>\n<p>draw.text((x, y), text, font=font, fill=&#39;black&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>ImageDraw<\/code>\u5bf9\u8c61\u5728\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6ce8\u91ca\u6587\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u751f\u6210\u542b\u6709\u52a8\u6001\u6570\u636e\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u751f\u6210\u5305\u542b\u52a8\u6001\u6570\u636e\u7684\u4e8c\u7ef4\u7801\uff0c\u4f8b\u5982\u5305\u542b\u5f53\u524d\u65f6\u95f4\u6233\u7684\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>timestamp = datetime.now().strftime(&#39;%Y-%m-%d %H:%M:%S&#39;)<\/p>\n<p>data = f&#39;Current Timestamp: {timestamp}&#39;<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\u5e76\u5c06\u5176\u4f5c\u4e3a\u6570\u636e\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\u548c\u4ee3\u7801\u793a\u4f8b\uff0c\u60a8\u5e94\u8be5\u5df2\u7ecf\u638c\u63e1\u4e86\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u548c\u5b9a\u5236\u4e8c\u7ef4\u7801\u3002<strong>\u5b89\u88c5\u76f8\u5173\u5e93\u3001\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u5b9a\u5236\u4e8c\u7ef4\u7801\u3001\u4fdd\u5b58\u548c\u663e\u793a\u4e8c\u7ef4\u7801<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u5173\u952e\u6b65\u9aa4\u3002\u65e0\u8bba\u662f\u751f\u6210\u7b80\u5355\u7684\u4e8c\u7ef4\u7801\uff0c\u8fd8\u662f\u751f\u6210\u542b\u6709Logo\u3001\u6ce8\u91ca\u6216\u52a8\u6001\u6570\u636e\u7684\u4e8c\u7ef4\u7801\uff0c<code>qrcode<\/code>\u548c<code>Pillow<\/code>\u5e93\u90fd\u80fd\u5e2e\u52a9\u60a8\u8f7b\u677e\u5b9e\u73b0\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u60a8\u63d0\u4f9b\u5b9e\u7528\u7684\u6307\u5bfc\uff0c\u52a9\u60a8\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u7075\u6d3b\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u4e8c\u7ef4\u7801\uff1f<\/strong><br \/>\u4f7f\u7528Python\u751f\u6210\u4e8c\u7ef4\u7801\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528<code>qrcode<\/code>\u5e93\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5\u8be5\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install qrcode[pil]<\/code>\u5b8c\u6210\u3002\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u4e8c\u7ef4\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import qrcode\n\ndata = &quot;https:\/\/www.example.com&quot;\nqr = qrcode.QRCode(version=1, box_size=10, border=5)\nqr.add_data(data)\nqr.make(fit=True)\n\nimg = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)\nimg.save(&quot;qrcode.png&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6307\u5b9a\u7f51\u5740\u7684\u4e8c\u7ef4\u7801\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n<p><strong>\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u7528\u4e8e\u54ea\u4e9b\u5e94\u7528\u573a\u666f\uff1f<\/strong><br \/>\u4e8c\u7ef4\u7801\u7684\u5e94\u7528\u573a\u666f\u975e\u5e38\u5e7f\u6cdb\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u4ea7\u54c1\u4fe1\u606f\u7684\u5feb\u901f\u5206\u4eab\u3001\u5728\u7ebf\u652f\u4ed8\u3001\u6d3b\u52a8\u5ba3\u4f20\u3001\u4e2a\u4eba\u540d\u7247\u3001\u7f51\u7ad9\u94fe\u63a5\u4ee5\u53ca\u793e\u4ea4\u5a92\u4f53\u7684\u63a8\u5e7f\u7b49\u3002\u901a\u8fc7\u626b\u63cf\u4e8c\u7ef4\u7801\uff0c\u7528\u6237\u53ef\u4ee5\u8fc5\u901f\u83b7\u53d6\u76f8\u5173\u4fe1\u606f\uff0c\u63d0\u5347\u4f53\u9a8c\u548c\u4fbf\u5229\u6027\u3002<\/p>\n<p><strong>\u751f\u6210\u4e8c\u7ef4\u7801\u65f6\u53ef\u4ee5\u81ea\u5b9a\u4e49\u54ea\u4e9b\u53c2\u6570\uff1f<\/strong><br \/>\u5728\u751f\u6210\u4e8c\u7ef4\u7801\u65f6\uff0c\u60a8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u591a\u4e2a\u53c2\u6570\uff0c\u4f8b\u5982\u4e8c\u7ef4\u7801\u7684\u7248\u672c\uff08\u63a7\u5236\u4fe1\u606f\u7684\u5bb9\u91cf\uff09\u3001\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u5927\u5c0f\uff08box_size\uff09\uff0c\u4ee5\u53ca\u4e8c\u7ef4\u7801\u7684\u8fb9\u6846\u5bbd\u5ea6\uff08border\uff09\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e8c\u7ef4\u7801\u7684\u524d\u666f\u8272\u548c\u80cc\u666f\u8272\uff0c\u4ece\u800c\u4f7f\u4e8c\u7ef4\u7801\u4e0e\u60a8\u7684\u54c1\u724c\u5f62\u8c61\u76f8\u5339\u914d\uff0c\u589e\u5f3a\u89c6\u89c9\u5438\u5f15\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u6765\u7f16\u5199\u4e8c\u7ef4\u7801 \u4f7f\u7528Python\u7f16\u5199\u4e8c\u7ef4\u7801\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u5b89\u88c5\u76f8\u5173\u5e93\u3001\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u5b9a\u5236\u4e8c\u7ef4\u7801\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1126267,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126257"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1126257"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126257\/revisions"}],"predecessor-version":[{"id":1126270,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126257\/revisions\/1126270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1126267"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1126257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1126257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1126257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}