{"id":77,"date":"2022-04-09T19:04:54","date_gmt":"2022-04-09T19:04:54","guid":{"rendered":"http:\/\/fanaticboy.com\/?p=77"},"modified":"2022-04-09T19:04:55","modified_gmt":"2022-04-09T19:04:55","slug":"%e6%b5%85%e8%b0%88python%e5%8f%af%e8%a7%86%e5%8c%96%e7%bc%96%e7%a8%8b%e4%b9%8btkinter%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fanaticboy.com\/?p=77","title":{"rendered":"\u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e00\uff09"},"content":{"rendered":"\n<p>\u200b<\/p>\n\n\n\n<p>&nbsp;\u54b1\u4eec\u5148\u8bbe\u7f6e\u8f93\u5165\u6846\u91cc\u9762\u7684\u503c\uff0c\u7136\u540e\u518d\u83b7\u53d6\u4e00\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>import tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen = tkinter.Tk()\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel = tkinter.Label(screen,text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.pack()\n#\u4ee5\u4e0b\u4e09\u884c\u4ee3\u7801\u4e00\u822c\u662f\u8fde\u7740\u7684\uff0c\u7b2c\u4e00\u884c\u662f\u4e3a\u4e86\u8bbe\u7f6e\u548c\u83b7\u53d6\u8f93\u5165\u7684\u6570\u636e\u7684\nu = tkinter.StringVar()\ntext = tkinter.Entry(screen, textvariable=u)\ntext.pack()\nu.set(\"hello\")\nprint(u.get())\n# \u4f7f\u7528mainloop\u65b9\u6cd5\u4f7f\u5f97\u7a97\u53e3\u663e\u793a\nscreen.mainloop()<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/9271e191-5858-402f-9fd6-6ef7deefccb8\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u6548\u679c\u5982\u56fe\u6240\u793a<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/f8a0e2ba759f2b30b0c033b6fb785cce.png\"><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/b8e7026c-dd13-4529-b54e-2eacee9a08a3\" width=\"15\" height=\"15\">\u200b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001button\u63a7\u4ef6<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u63a7\u4ef6\u4e5f\u5c31\u662f\u6309\u94ae\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u5b9e\u73b0\u4e00\u4e9b\u529f\u80fd\uff0c\u90a3\u8fd9button\u662f\u600e\u4e48\u6dfb\u52a0\u7684\u5462\uff0c\u4ee5\u53ca\u91cc\u9762\u7684\u529f\u80fd\u662f\u600e\u6837\u5b9e\u73b0\u7684\u5462\uff0c\u6765\u4e0a\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen = tkinter.Tk()\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel = tkinter.Label(screen,text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.pack()\n#\u4ee5\u4e0b\u4e09\u884c\u4ee3\u7801\u4e00\u822c\u662f\u8fde\u7740\u7684\uff0c\u7b2c\u4e00\u884c\u662f\u4e3a\u4e86\u8bbe\u7f6e\u548c\u83b7\u53d6\u8f93\u5165\u7684\u6570\u636e\u7684\nu = tkinter.StringVar()\ntext = tkinter.Entry(screen, textvariable=u)\ntext.pack()\nu.set(\"hello\")\ndef run():\n    print(u.get())\n\n# \u5176\u4e2dcommend\u7684\u503c\u5c31\u662f\u51fd\u6570\u540d\nbutton = tkinter.Button(screen, text=\"\u70b9\u6211\", command=run)\nbutton.pack()\n# \u4f7f\u7528mainloop\u65b9\u6cd5\u4f7f\u5f97\u7a97\u53e3\u663e\u793a\nscreen.mainloop()<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/ae6c8b25-42f5-4c2f-808b-e8fa48c8ba84\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u6548\u679c\u5982\u56fe<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/9802450a5b71e2e1fdcfdc113fa14324.png\"><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/7df646e7-6b9f-45ad-a844-e39f55e70b08\" width=\"15\" height=\"15\">\u200b<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u603b\u7ed3<\/h1>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662ftkinter\u7684\u4e00\u4e9b\u57fa\u7840\u90e8\u5206\u7684\u8bb2\u89e3\u4e86\uff0c\u76f8\u4fe1\u5927\u5bb6\u4e5f\u6709\u4e86\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u90a3\u4e48\u4e0b\u4e00\u7bc7\u4f1a\u66f4\u65b0\u4e2d\u7ea7\u7684\u90e8\u5206\uff0c\u597d\u4e86\u559c\u6b22\u7684\u8bdd\u5c31\u8bf7\u70b9\u4e2a\u8d5e\u518d\u8d70\u5457\uff01 \u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b &nbsp;\u54b1\u4eec\u5148\u8bbe\u7f6e\u8f93\u5165\u6846\u91cc\u9762\u7684\u503c\uff0c\u7136\u540e\u518d\u83b7\u53d6\u4e00\u4e0b \u6548\u679c\u5982\u56fe\u6240\u793a \u200b 3\u3001button\u63a7\u4ef6 \u8fd9\u4e2a\u63a7\u4ef6\u4e5f\u5c31 &#8230; <a title=\"\u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e00\uff09\" class=\"read-more\" href=\"https:\/\/fanaticboy.com\/?p=77\" aria-label=\"\u9605\u8bfb \u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e00\uff09\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,16],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-python","category-tkinter"],"_links":{"self":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":1,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}