{"id":218,"date":"2021-07-05T15:00:17","date_gmt":"2021-07-05T07:00:17","guid":{"rendered":"https:\/\/himpqblog.cn\/?p=218"},"modified":"2021-07-05T15:00:20","modified_gmt":"2021-07-05T07:00:20","slug":"%e6%96%87%e7%ab%a0","status":"publish","type":"post","link":"https:\/\/himpqblog.cn\/index.php\/archives\/218","title":{"rendered":"Python \u5faa\u73af\u8bed\u53e5\u9047\u4e0a\u533f\u51fd"},"content":{"rendered":"\n<p>\u5f53\u4f60\u60f3\u7528\u5faa\u73af\u8bed\u53e5\u5728tkinter\u6216\u8005\u65e0\u8bba\u67d0\u4e2a\u51fd\u53c2\u4e2d\u5199\u4e00\u4e2a\u5e26\u53c2\u7684\u51fd\u6570\uff0c\u4f60\u53ef\u80fd\u4f1a\u78b0\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">def e(n):\r\n\t<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"E\"<\/span>, n)\nt = &#91;]\n<span class=\"hljs-keyword\">for<\/span> i in range(<span class=\"hljs-number\">10<\/span>):\r\n\tt.append(lambda: e(i))\n<span class=\"hljs-keyword\">for<\/span> p in t:\r\n\tp()\n\n<span class=\"hljs-comment\">#Output<\/span>\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span>\r\nE <span class=\"hljs-number\">9<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>\u4ee5\u4e0a\u5c3d\u7ba1\u76f4\u63a5\u770b\u4e0d\u5e38\u89c1\uff0c\u4f46\u662f\u4f1a\u51fa\u73b0\u5728\u5f88\u591atkinter\u8bed\u53e5\u4e2d\uff0c\u6bd4\u5982tkinter\u7684\u6309\u94ae\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\nroot = tk.Tk()\n\ndef pr(xxx):\n    print(xxx)\n\n<span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">10<\/span>):\n    g = tk.Button(root, text = str(i), \n                  command = lambda: pr(i)\n                 )\n    g.pack()\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>\u770b\u5230\u95ee\u9898\u51fa\u73b0\u5728\u54ea\u4e86\u5417\uff1f<\/p>\n\n\n\n<p>\u4f60\u60f3\u8981\u7ed9\u6bcf\u4e2a\u6309\u94ae\u89e6\u53d1\u4e8b\u4ef6\u4e00\u4e2aID\uff0c\u4f46\u662ftkinter\u89e6\u53d1\u4e8b\u4ef6\u76f4\u63a5\u7528 <strong><em>command = xxx<\/em><\/strong> \u4e0d\u80fd\u5e26\u53c2\u6570\uff0c\u6240\u4ee5\u4f60\u9009\u62e9\u4e86\u533f\u540d\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u53c8\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u6b63\u5982\u5f00\u5934\u6240\u8bb2\uff0c\u8fd9\u6837\u7684\u683c\u5f0f\u6700\u540e\u4f1a\u5bfc\u81f4 <strong><em>\u53d8\u91cf i<\/em><\/strong> \u53d8\u6210\u5faa\u73af\u6700\u540e\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"786\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2021\/07\/\u52a8\u753b.gif\" alt=\"\" class=\"wp-image-220\"\/><\/figure>\n\n\n\n<p>\u533f\u540d\u51fd\u6570\u5982\u540c\u6b63\u5e38\u51fd\u6570\u4e00\u6837\uff0c\u4e0d\u4f1a\u5728\u5b9a\u4e49\u65f6\u5c31\u76f4\u63a5\u83b7\u53d6ID\uff0c\u800c\u662f\u8c03\u7528\u540e\u518d\u83b7\u53d6\uff0c\u56e0\u6b64\u4f1a\u53d8\u6210\u56fe\u4e2d\u7684 <strong><em>9<\/em><\/strong> \uff08\u5373 <strong><em>range(10)[-1]<\/em><\/strong>\uff09<\/p>\n\n\n\n<p>\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n\n\n\n<p>\u4e0d\u8981\u60f3\u7740\u5c06\u503c\u8d4b\u7ed9\u6309\u94ae\u5bf9\u8c61\uff0c\u56e0\u4e3a\u533f\u540d\u51fd\u6570\u83b7\u53d6\u7684\u6309\u94ae\u5bf9\u8c61\u4e5f\u662f\u6700\u540e\u4e00\u4e2a\u6309\u94ae\u3002<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">command = lambda n=i: pr(n)  <span class=\"hljs-comment\">#\u5c06\u539fcommand\u53c2\u6570\u8fd9\u4e00\u884c\u66ff\u6362\u5373\u53ef<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>\u51fd\u6570\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\u4f1a\u7acb\u5373\u83b7\u53d6\uff0c\u6240\u4ee5n\u5c31\u662f\u5f53\u524d\u7684i\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u6269\u5c55\u4e00\u4e0b\uff0c\u6211\u5728\u4e00\u672c\u4e66\u4e0a\u770b\u8fc7\uff0c\u4f3c\u4e4e\u5f53\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u9ed8\u8ba4\u4e3a\u5217\u8868\u65f6\u5019\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">def f(n, a=&#91;]):\n    a.append(n)\n    <span class=\"hljs-keyword\">print<\/span>(a)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>\u4f60\u6267\u884c\u7b2c\u4e00\u6b21f(1)\uff0c\u7b2c\u4e8c\u6b21f(2)\uff0c\u7b2c\u4e09\u6b21f(3)\uff0c\u4e0a\u9762\u7684 a \u53c2\u6570\u4f1a\u4f9d\u65e7\u4fdd\u5b58\u4e0a\u4e00\u6b21\u6267\u884c\u65f6\u5019\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u542c\u4e0d\u660e\u767d\uff1f\u6ca1\u5173\u7cfb\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"191\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2021\/07\/image-1.png\" alt=\"\" class=\"wp-image-221\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u60f3\u7528\u5faa\u73af\u8bed\u53e5\u5728tkinter\u6216\u8005\u65e0\u8bba\u67d0\u4e2a\u51fd\u53c2\u4e2d\u5199\u4e00\u4e2a\u5e26\u53c2\u7684\u51fd\u6570\uff0c\u4f60\u53ef\u80fd\u4f1a\u78b0\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff1a \u4ee5\u4e0a\u5c3d\u7ba1\u76f4\u63a5\u770b\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":1,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":222,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/218\/revisions\/222"}],"wp:attachment":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}