{"id":84,"date":"2022-04-09T19:10:33","date_gmt":"2022-04-09T19:10:33","guid":{"rendered":"http:\/\/fanaticboy.com\/?p=84"},"modified":"2022-04-09T19:10:34","modified_gmt":"2022-04-09T19:10:34","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%ba%8c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fanaticboy.com\/?p=84","title":{"rendered":"\u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e8c\uff09"},"content":{"rendered":"\n<p>\u200b<\/p>\n\n\n\n<p>\u4e0a\u4e00\u7bc7\u54b1\u4eec\u8bb2\u4e86tkinter\u7684\u57fa\u7840\u90e8\u5206\uff0c\u5e03\u5c40\u4e5f\u662f\u76f8\u5f53\u7684\u7b80\u964b\u3002\u4f4d\u7f6e\u4e5f\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u6211\u4eec\u5b9e\u9645\u8bbe\u8ba1\u7684\u65f6\u5019\uff0c\u6216\u8005\u81ea\u5df1\u7f16\u5199\u5e03\u5c40\u7684\u65f6\u5019\u5e0c\u671b\u662f\u81ea\u7531\u7684\u3002\u81ea\u5df1\u53ef\u4ee5\u968f\u610f\u7684\u8c03\u6574\u63a7\u4ef6\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u624d\u6709\u81ea\u5df1\u7684\u611f\u89c9\uff0c\u6240\u4ee5\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u662f\u8bf4\u4e00\u4e0b\u4e2d\u9636\u90e8\u5206\uff0c\u5982\u4f55\u8c03\u6574\u5404\u4e2a\u63a7\u4ef6\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5404\u4e2a\u63a7\u4ef6\u7684\u4f4d\u7f6e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\u3001Label\u63a7\u4ef6\u7684\u4f4d\u7f6e<\/h3>\n\n\n\n<p>\u54b1\u4eec\u4ee5\u4e0a\u6b21\u7684\u4f5c\u4e3a\u57fa\u7840\u8fdb\u884c\u5c0f\u5c0f\u7684\u66f4\u6539\uff0c\u770b\u770b\u6548\u679c\u662f\u600e\u4e48\u6837\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen&nbsp;=&nbsp;tkinter.Tk()\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel&nbsp;=&nbsp;tkinter.Label(screen,text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.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\/d3d48341-7e27-4910-9c47-3afb12d2ba8c\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u662f\u539f\u6765\u7684\uff0c\u60f3\u8981\u81ea\u5df1\u8bbe\u8ba1\u4f4d\u7f6e\u9700\u8981\u6539label.pack\uff08\uff09\u8fd9\u4e2a\u5730\u65b9\u3002\u5177\u4f53\u7684\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen&nbsp;=&nbsp;tkinter.Tk()\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel&nbsp;=&nbsp;tkinter.Label(screen,text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.place(x=30,&nbsp;y=50)\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\/929febfb-29ec-45a7-a298-1a2e13e94d06\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/30c72f9c92169450123e6f19a3d78908.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/531d1f1b-5ca2-48ae-ab34-7681ccd6460a\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u4e0a\u56fe\u5c31\u662f\u6539\u4e86\u4e4b\u540e\u7684\u6807\u7b7e\u7684\u4f4d\u7f6e\uff0c\u4e24\u4e2a\u91cd\u8981\u7684\u5173\u952e\u5b57\u53c2\u6570\uff0cx\u548cy\uff0c\u5c31\u662f\u4e24\u4e2a\u5750\u6807\uff0c\u6a2a\u5750\u6807\u548c\u7eb5\u5750\u6807\uff0c\u81ea\u5df1\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u6765\u8c03\u6574<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2\u3001entry\u63a7\u4ef6\u7684\u4f4d\u7f6e<\/h3>\n\n\n\n<p>\u548clebel\u4e00\u6837\u7684\u64cd\u4f5c\uff0c\u4ee3\u7801\u5982\u4e0b\uff0c\u7136\u540e\u770b\u56fe<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen&nbsp;=&nbsp;tkinter.Tk()\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel&nbsp;=&nbsp;tkinter.Label(screen,text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.place(x=30,&nbsp;y=50)\nu&nbsp;=&nbsp;tkinter.StringVar()\ntext&nbsp;=&nbsp;tkinter.Entry(screen,&nbsp;textvariable=u)\ntext.place(x=120,&nbsp;y=50)\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\/d67e8a0b-668d-4d24-9d5b-c22baaafc8c6\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/c4d4895c5000d9f3eb41074af5f22e4c.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/e7f1b201-5468-4f1e-aa0d-6cc8b350a396\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3\u3001button\u63a7\u4ef6\u7684\u4f4d\u7f6e<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u4e5f\u662f\u5148\u770b\u4ee3\u7801\u540e\u770b\u56fe<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;tkinter\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen&nbsp;=&nbsp;tkinter.Tk()\n# \u8bbe\u7f6e\u7a97\u53e3\u7684\u4f4d\u7f6e\u4ee5\u53ca\u5927\u5c0f\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel&nbsp;=&nbsp;tkinter.Label(screen,&nbsp;text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.place(x=30,&nbsp;y=50)\n\nu&nbsp;=&nbsp;tkinter.StringVar()\ntext&nbsp;=&nbsp;tkinter.Entry(screen,&nbsp;textvariable=u)\ntext.place(x=120,&nbsp;y=50)\nu.set(\"hello\")\ndef&nbsp;run():\n&nbsp; &nbsp;print(u.get())\n# \u5176\u4e2dcommend\u7684\u503c\u5c31\u662f\u51fd\u6570\u540d\nbutton&nbsp;=&nbsp;tkinter.Button(screen,&nbsp;text=\"\u70b9\u6211\",&nbsp;command=run)\nbutton.place(x=120,&nbsp;y=70)\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\/0fe2ee82-51fe-4df4-bf0e-2472d526d542\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/3e5115d5027ff6308ea3a2cbe8ef8337.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/ea6fa285-a611-4a04-997e-fe6a90aa3184\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u7a97\u53e3\u663e\u793a\u7684\u4f4d\u7f6e<\/h1>\n\n\n\n<p>\u5927\u5bb6\u662f\u4e0d\u662f\u8fd0\u884c\u7a0b\u5e8f\u7684\u65f6\u5019\u7a97\u53e3\u9ed8\u8ba4\u51fa\u73b0\u5728\u5de6\u4e0a\u89d2\uff0c\u800c\u4e14\u8fd8\u5f88\u5c0f\uff0c\u90a3\u4e48\u8fd9\u91cc\u6559\u5927\u5bb6\u600e\u4e48\u8bbe\u7f6e\u4f4d\u7f6e\u4ee5\u53ca\u5927\u5c0f\u3002\u8981\u7528\u5230geometry()\u51fd\u6570\u5177\u4f53\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;tkinter\n\n# \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\nscreen&nbsp;=&nbsp;tkinter.Tk()\n# \u8bbe\u7f6e\u7a97\u53e3\u7684\u4f4d\u7f6e\u4ee5\u53ca\u5927\u5c0f\nscreen.geometry(\"800x600+300+50\")\n# \u521b\u5efalabel\u5bf9\u8c61\nlabel&nbsp;=&nbsp;tkinter.Label(screen,&nbsp;text=\"\u8fd9\u662flabel\u63a7\u4ef6\")\n# \u663e\u793alabel,pack\u51fd\u6570\u662f\u81ea\u9002\u5e94\nlabel.place(x=30,&nbsp;y=50)\nu&nbsp;=&nbsp;tkinter.StringVar()\ntext&nbsp;=&nbsp;tkinter.Entry(screen,&nbsp;textvariable=u)\ntext.place(x=120,&nbsp;y=50)\nu.set(\"hello\")\ndef&nbsp;run():\n&nbsp; &nbsp;print(u.get())\n# \u5176\u4e2dcommend\u7684\u503c\u5c31\u662f\u51fd\u6570\u540d\nbutton&nbsp;=&nbsp;tkinter.Button(screen,&nbsp;text=\"\u70b9\u6211\",&nbsp;command=run)\nbutton.place(x=120,&nbsp;y=70)\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\/1ffa064d-d517-486e-b719-a86c3d69dc4f\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/a966330b1739f3eeef36160c6717407f.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/40549255-484d-4737-a367-cc103b321afc\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>geometry(&#8220;800&#215;600+300+50&#8221;)\u91cc\u9762\u7684\u53c2\u6570800\u548c600\u4e4b\u95f4\u7684\u662fXYZ\u7684X\uff0c\u4e0d\u662f*<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662ftkinter\u7684\u4e2d\u9636\u7684\u90e8\u5206\u4e86\uff0c\u63a5\u4e0b\u6765\u7684\u4e00\u7bc7\u51c6\u5907\u8bb2\u8bb2\u600e\u4e48\u5728\u7a97\u53e3\u4e0a\u52a0\u4e0a\u83dc\u5355\uff0c\u8ba9\u7a97\u53e3\u770b\u8d77\u6765\u66f4\u52a0\u4e13\u4e1a\u4e00\u4e9b \u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b \u4e0a\u4e00\u7bc7\u54b1\u4eec\u8bb2\u4e86tkinter\u7684\u57fa\u7840\u90e8\u5206\uff0c\u5e03\u5c40\u4e5f\u662f\u76f8\u5f53\u7684\u7b80\u964b\u3002\u4f4d\u7f6e\u4e5f\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u6211\u4eec\u5b9e\u9645\u8bbe\u8ba1\u7684\u65f6\u5019\uff0c\u6216\u8005\u81ea\u5df1 &#8230; <a title=\"\u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e8c\uff09\" class=\"read-more\" href=\"https:\/\/fanaticboy.com\/?p=84\" aria-label=\"\u9605\u8bfb \u6d45\u8c08python\u53ef\u89c6\u5316\u7f16\u7a0b\u4e4btkinter\uff08\u4e8c\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-84","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\/84","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=84"}],"version-history":[{"count":1,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/84\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}