﻿{"id":3922,"date":"2020-11-10T21:15:10","date_gmt":"2020-11-10T13:15:10","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=3922"},"modified":"2020-11-10T21:19:53","modified_gmt":"2020-11-10T13:19:53","slug":"python-mima","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/python-mima.html","title":{"rendered":"Python\u5b9e\u6218\u9879\u76ee &#8211; \u5236\u4f5c\u81ea\u5df1\u7684Python\u5bc6\u7801\u751f\u6210\u5668"},"content":{"rendered":"<p><strong>\u4e86\u89e3\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u5bc6\u7801\u751f\u6210\u5668\u3002<\/strong><\/p>\n<p>\u6211\u4eec\u77e5\u9053\u5bc6\u7801\u662f\u771f\u6b63\u7684\u5b89\u5168\u5a01\u80c1\u3002\u4e3a\u4e86\u786e\u4fdd\u60a8\u7684\u5e10\u6237\u5b89\u5168\u5e76\u9632\u6b62\u5bc6\u7801\u88ab\u9ed1\u5ba2\u5165\u4fb5\uff0c\u60a8\u5fc5\u987b\u5c06\u5bc6\u7801\u8bbe\u7f6e\u5f97\u8db3\u591f\u5f3a\u5927\uff0c\u4ee5\u81f3\u4e8e\u6ca1\u4eba\u80fd\u731c\u5230\u3002<\/p>\n<p><strong>\u5bc6\u7801\u751f\u6210\u5668<\/strong><\/p>\n<p>\u5b83\u662f\u4e00\u79cd\u5de5\u5177\uff0c\u53ef\u6839\u636e\u60a8\u8bbe\u7f6e\u7684\u7ed9\u5b9a\u51c6\u5219\u751f\u6210\u5bc6\u7801\uff0c\u4e3a\u60a8\u7684\u5e10\u6237\u521b\u5efa\u4e00\u4e2a\u4e0d\u53ef\u9884\u77e5\u7684\u5f3a\u5bc6\u7801\u3002<\/p>\n<p>\u5bc6\u7801\u751f\u6210\u5668\u5de5\u5177\u4f1a\u4e3a\u7528\u6237\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u7684\uff0c\u81ea\u5b9a\u4e49\u7684\u5bc6\u7801\uff0c\u4ee5\u5e2e\u52a9\u4ed6\u4eec\u521b\u5efa\u5b89\u5168\u6027\u66f4\u9ad8\u7684\u5bc6\u7801\u3002<\/p>\n<p><strong>\u5bc6\u7801\u751f\u6210\u5668Python\u9879\u76ee<\/strong><\/p>\n<p>\u8be5\u9879\u76ee\u7684\u76ee\u7684\u662f\u4f7f\u7528python\u521b\u5efa\u5bc6\u7801\u751f\u6210\u5668\u3002\u5bc6\u7801\u751f\u6210\u5668\u9879\u76ee\u5c06\u4f7f\u7528Tkinter\uff0crandom\uff0cstring\uff0cpyperclip\u7b49python\u6a21\u5757\u6784\u5efa\u3002<\/p>\n<p>\u5728\u8be5\u9879\u76ee\u4e2d\uff0c\u7528\u6237\u5fc5\u987b\u9009\u62e9\u5bc6\u7801\u957f\u5ea6\uff0c\u7136\u540e\u5355\u51fb\u201c <b>\u751f\u6210\u5bc6\u7801<\/b>\u201d\u6309\u94ae\u3002\u5b83\u5c06\u5728\u4e0b\u9762\u663e\u793a\u751f\u6210\u7684\u5bc6\u7801\u3002\u5982\u679c\u7528\u6237\u5355\u51fb\u201c<strong>\u590d\u5236\u5230\u526a\u8d34\u677f<\/strong>\u201d\u6309\u94ae\uff0c\u5b83\u5c06\u81ea\u52a8\u590d\u5236\u5bc6\u7801\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3924 size-full\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/11\/password.png\" alt=\"\" width=\"602\" height=\"639\" \/><\/p>\n<p class=\"fittexted_for_content_h3\"><strong>\u9879\u76ee\u5148\u51b3\u6761\u4ef6<\/strong><\/p>\n<p>\u4e3a\u4e86\u6784\u5efa\u8fd9\u4e2a\u9879\u76ee\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Python\u548c\u5e93\u7684\u57fa\u672c\u6982\u5ff5\u2013 Tkinter\uff0cpyperclip\uff0crandom\uff0cstring\u3002<\/p>\n<ul>\n<li><strong>Tkinter<\/strong>\u662f\u6807\u51c6\u7684GUI\u5e93\uff0c\u5e76\u4e14\u662f\u6784\u5efaGUI\u5e94\u7528\u7a0b\u5e8f\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u4e4b\u4e00\u3002<\/li>\n<li><strong>pyperclip<\/strong>\u6a21\u5757\u5141\u8bb8\u6211\u4eec\u5728\u526a\u8d34\u677f\u4e4b\u95f4\u590d\u5236\u6587\u672c\u5e76\u5c06\u5176\u7c98\u8d34\u5230\u60a8\u7684\u8ba1\u7b97\u673a<\/li>\n<li><strong>random<\/strong>\u6a21\u5757\u53ef\u4ee5\u751f\u6210\u968f\u673a\u6570<\/li>\n<li>string\u6a21\u5757\u5305\u542b\u8bb8\u591a\u7528\u4e8e\u5904\u7406\u6807\u51c6python\u5b57\u7b26\u4e32\u7684\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p>\u8981\u5b89\u88c5\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u4f7f\u7528pip\u5b89\u88c5\uff1a<\/p>\n<pre class=\"enlighter-clipboard\">pip install tkinter\r\npip install pyperclip\r\npip install random\r\npip install strings<\/pre>\n<h3 class=\"fittexted_for_content_h3\">\u9879\u76ee\u6587\u4ef6\u7ed3\u6784<\/h3>\n<p>\u8ba9\u6211\u4eec\u4e86\u89e3\u638c\u63e1\u4e0b\u4f7f\u7528Python\u6784\u5efa\u5bc6\u7801\u751f\u6210\u5668\u7684\u6b65\u9aa4<\/p>\n<ul>\n<li>\u5bfc\u5165\u6a21\u5757<\/li>\n<li>\u521d\u59cb\u5316\u7a97\u53e3<\/li>\n<li>\u9009\u62e9\u5bc6\u7801\u957f\u5ea6<\/li>\n<li>\u5b9a\u4e49\u529f\u80fd<\/li>\n<\/ul>\n<h3 class=\"fittexted_for_content_h3\">\u521b\u5efa\u968f\u673a\u5bc6\u7801\u751f\u6210\u5668\u7684\u6b65\u9aa4<\/h3>\n<h4 class=\"fittexted_for_content_h4\">1\u3001\u5bfc\u5165\u5e93<\/h4>\n<p>\u7b2c\u4e00\u6b65\u662f\u5bfc\u5165\u5e93<\/p>\n<pre class=\"enlighter-clipboard\">from tkinter import *\r\nimport random, string\r\nimport pyperclip<\/pre>\n<h4 class=\"fittexted_for_content_h4\">2\u3001\u521d\u59cb\u5316\u7a97\u53e3<\/h4>\n<pre class=\"enlighter-clipboard\">root = Tk()\r\nroot.geometry(\"600x600\")\r\nroot.resizable(0,0)\r\nroot.title(\"www.linuxmi.com - \u5bc6\u7801\u751f\u6210\u5668\")<\/pre>\n<ul>\n<li><strong>Tk() <\/strong>\u521d\u59cb\u5316\u4e86tkinter\uff0c\u8fd9\u610f\u5473\u7740\u521b\u5efa\u4e86\u7a97\u53e3<\/li>\n<li><strong>geometry() <\/strong>\u8bbe\u7f6e\u7a97\u53e3\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6<\/li>\n<li><strong>resizable(0,0\uff09<\/strong>\u8bbe\u7f6e\u7a97\u53e3\u7684\u56fa\u5b9a\u5927\u5c0f<\/li>\n<li><strong>title()<\/strong>\u8bbe\u7f6e\u7a97\u53e3\u7684\u6807\u9898<\/li>\n<\/ul>\n<pre class=\"enlighter-clipboard\">Label(root, text = '\u5bc6\u7801\u751f\u6210\u5668' , font ='arial 15 bold').pack()\r\nLabel(root, text ='Linux\u8ff7 www.linuxmi.com', font ='arial 15 bold').pack(side = BOTTOM)<\/pre>\n<p><strong>Label()<\/strong>\u5c0f\u90e8\u4ef6\u7528\u4e8e\u663e\u793a\u7528\u6237\u65e0\u6cd5\u4fee\u6539\u7684\u4e00\u884c\u6216\u591a\u884c\u6587\u672c\u3002<\/p>\n<ul>\n<li><strong>root<\/strong>\u662f\u6211\u4eec\u5728\u7a97\u53e3\u4e2d\u5f15\u7528\u7684\u540d\u79f0<\/li>\n<li><strong>text<\/strong> \u6211\u4eec\u5728\u6807\u7b7e\u4e0a\u663e\u793a\u7684\u662f\u4ec0\u4e48<\/li>\n<li><strong>font<\/strong> \u6587\u672c\u7684\u5b57\u4f53<\/li>\n<li><strong>pack<\/strong> \u6309\u5757\u7ec4\u7ec7\u7684\u5c0f\u90e8\u4ef6<\/li>\n<\/ul>\n<h4 class=\"fittexted_for_content_h4\">3\u3001\u9009\u62e9\u5bc6\u7801\u957f\u5ea6<\/h4>\n<pre class=\"enlighter-clipboard\">pass_label = Label(root, text = '\u5bc6\u7801\u957f\u5ea6', font = 'arial 10 bold').pack()\r\npass_len = IntVar()\r\nlength = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack()<\/pre>\n<ul>\n<li><strong>pass_len<\/strong>\u662f\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u7528\u4e8e\u5b58\u50a8\u5bc6\u7801\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u8981\u9009\u62e9\u5bc6\u7801\u957f\u5ea6\uff0c\u6211\u4eec\u4f7f\u7528<strong>Spinbox()<\/strong>\u5c0f\u90e8\u4ef6\u3002<\/li>\n<li><strong>Spinbox() <\/strong>\u5c0f\u90e8\u4ef6\u7528\u4e8e\u4ece\u56fa\u5b9a\u6570\u91cf\u7684\u503c\u4e2d\u8fdb\u884c\u9009\u62e9\u3002\u8fd9\u91cc\u7684\u503c\u4ece8\u523032<\/li>\n<\/ul>\n<h4 class=\"fittexted_for_content_h4\">4\u3001\u751f\u6210\u5bc6\u7801\u7684\u51fd\u6570<\/h4>\n<pre class=\"enlighter-clipboard\">pass_str = StringVar()\r\ndef Generator():\r\n    password = ''\r\n\r\n    for x in range (0,4):\r\n        Password = random.choice(string.ascii_uppercase) + random.choice(string.ascii_lowercase) + random.choice(string.digits) + random.choice(string.punctuation)\r\n    for y in range(pass_len.get()- 4):\r\n        password = password + random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation)\r\n    pass_str.set(password)<\/pre>\n<ul>\n<li><strong>pass_str<\/strong>\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u7528\u4e8e\u5b58\u50a8\u751f\u6210\u7684\u5bc6\u7801<\/li>\n<li><strong>password<\/strong>\u00a0= \u201c\u201d\u662f\u7a7a\u5b57\u7b26\u4e32<\/li>\n<li>\u7b2c\u4e00\u4e2a\u5faa\u73af\u5c06\u751f\u6210\u4e00\u4e2a\u957f\u5ea6\u4e3a4\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u662f\u5927\u5199\u5b57\u6bcd\uff0c\u5c0f\u5199\u5b57\u6bcd\uff0c\u6570\u5b57\u548c\u7279\u6b8a\u7b26\u53f7\u7684\u7ec4\u5408\uff0c\u8be5\u5b57\u7b26\u4e32\u5c06\u5b58\u50a8\u5728password\u53d8\u91cf\u4e2d\u3002<\/li>\n<li>\u7b2c\u4e8c\u4e2a\u5faa\u73af\u5c06\u751f\u6210\u7531\u7528\u6237\u8f93\u5165\u7684\u957f\u5ea6\u4e3a4\u7684\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230password\u53d8\u91cf\u4e2d\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u51cf\u53bb\u7528\u6237\u957f\u5ea6\u4e3a4\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u751f\u6210\u4e86\u957f\u5ea6\u4e3a4\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u6837\u505a\u662f\u56e0\u4e3a\u6211\u4eec\u60f3\u8981\u4e00\u4e2a\u5bc6\u7801\uff0c\u8be5\u5bc6\u7801\u5fc5\u987b\u5305\u542b\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff0c\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e00\u4e2a\u6570\u5b57\u548c\u4e00\u4e2a\u7279\u6b8a\u7b26\u53f7\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u5c06\u5bc6\u7801\u8bbe\u7f6e\u4e3a<strong>pass_str() <\/strong>\u53d8\u91cf\u3002<\/p>\n<pre class=\"enlighter-clipboard\">Button(root, text = \"\u751f\u6210\u5bc6\u7801\" , command = Generator ).pack(pady= 5)\r\nEntry(root , textvariable = pass_str).pack()<\/pre>\n<ul>\n<li><strong>Button() <\/strong>\u5c0f\u90e8\u4ef6\uff0c\u7528\u4e8e\u5728\u6211\u4eec\u7684\u7a97\u53e3\u4e0a\u663e\u793a\u6309\u94ae<\/li>\n<li><strong>command<\/strong> \u5f53\u5355\u51fb\u6309\u94ae\u65f6\u8c03\u7528<\/li>\n<li><strong>Entry() <\/strong>\u7528\u4e8e\u521b\u5efa\u8f93\u5165\u6587\u672c\u5b57\u6bb5\u7684\u5c0f\u90e8\u4ef6<\/li>\n<li><strong>textvariable <\/strong>\u7528\u4e8e\u5c06\u5f53\u524d\u6587\u672c\u68c0\u7d22\u5230\u8f93\u5165\u5c0f\u90e8\u4ef6<\/li>\n<\/ul>\n<h4 class=\"fittexted_for_content_h4\">5\u3001\u590d\u5236\u5bc6\u7801\u7684\u51fd\u6570<\/h4>\n<pre class=\"enlighter-clipboard\">def Copy_password():\r\n    pyperclip.copy(pass_str.get())\r\n\r\nButton(root, text = '\u590d\u5236\u5230\u526a\u8d34\u677f', command = Copy_password).pack(pady=5)<\/pre>\n<h2 class=\"fittexted_for_content_h2\">\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5730\u4f7f\u7528python\u521b\u5efa\u4e86\u4e00\u4e2a\u968f\u673a\u5bc6\u7801\u751f\u6210\u5668\u9879\u76ee\u3002\u6211\u4eec\u4f7f\u7528\u4e86\u6d41\u884c\u7684tkinter\u5e93\u5728\u663e\u793a\u7a97\u53e3\u4e2d\u6e32\u67d3\u56fe\u5f62\uff0c\u5e76\u4e14\u8fd8\u4e86\u89e3\u4e86pyperclip\u548c\u968f\u673a\u5e93\u3002<\/p>\n<p>\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u521b\u5efa\u6309\u94ae\uff0c\u8f93\u5165\u6587\u672c\u5b57\u6bb5\uff0c\u6807\u7b7e\u548cSpinbox\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u6210\u529f\u521b\u5efa\u4e86\u5bc6\u7801\u751f\u6210\u5668python\u9879\u76ee\u3002\u5e0c\u671b\u4f60\u559c\u6b22\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u5bc6\u7801\u751f\u6210\u5668\u3002 \u6211\u4eec\u77e5\u9053\u5bc6\u7801\u662f\u771f\u6b63\u7684\u5b89\u5168\u5a01\u80c1\u3002\u4e3a\u4e86\u786e\u4fdd\u60a8\u7684\u5e10\u6237\u5b89\u5168 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3922","post","type-post","status-publish","format-standard","hentry","category-qita"],"aioseo_notices":[],"views":767,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/3922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=3922"}],"version-history":[{"count":3,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/3922\/revisions"}],"predecessor-version":[{"id":3926,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/3922\/revisions\/3926"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=3922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=3922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=3922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}