{"id":204576,"date":"2025-05-29T11:26:20","date_gmt":"2025-05-29T03:26:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204576\/"},"modified":"2025-05-29T11:26:20","modified_gmt":"2025-05-29T03:26:20","slug":"%e4%bd%bf%e7%94%a8-grid-%e5%b8%83%e5%b1%80%e7%ae%a1%e7%90%86%e5%99%a8%e5%88%9b%e5%bb%ba-gui-%e7%aa%97%e5%8f%a3%ef%bc%9a%e5%a6%82%e4%bd%95%e5%b0%86%e4%b8%89%e4%b8%aa%e6%a0%87%e7%ad%be%e3%80%81%e4%b8%a4","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204576\/","title":{"rendered":"\u4f7f\u7528 Grid \u5e03\u5c40\u7ba1\u7406\u5668\u521b\u5efa GUI \u7a97\u53e3\uff1a\u5982\u4f55\u5c06\u4e09\u4e2a\u6807\u7b7e\u3001\u4e24\u4e2a\u6587\u672c\u6846\u548c\u4e00\u4e2a\u6309\u94ae\u5e03\u5c40\u5e76\u5b9e\u73b0\u6c42\u548c\u529f\u80fd\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528 Grid \u5e03\u5c40\u7ba1\u7406\u5668\u521b\u5efa GUI \u7a97\u53e3\uff1a\u5982\u4f55\u5c06\u4e09\u4e2a\u6807\u7b7e\u3001\u4e24\u4e2a\u6587\u672c\u6846\u548c\u4e00\u4e2a\u6309\u94ae\u5e03\u5c40\u5e76\u5b9e\u73b0\u6c42\u548c\u529f\u80fd\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u4f7f\u7528 Grid \u5e03\u5c40\u7ba1\u7406\u5668\u521b\u5efa GUI \u7a97\u53e3\uff1a\u5982\u4f55\u5c06\u4e09\u4e2a\u6807\u7b7e\u3001\u4e24\u4e2a\u6587\u672c\u6846\u548c\u4e00\u4e2a\u6309\u94ae\u5e03\u5c40\u5e76\u5b9e\u73b0\u6c42\u548c\u529f\u80fd\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/173128611767315465b7ec2.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>grid \u5e03\u5c40\u7ba1\u7406\u5668\u5728 gui \u7a97\u53e3\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<p>\u5728 gui \u7f16\u7a0b\u4e2d\uff0cgrid \u5e03\u5c40\u7ba1\u7406\u5668\u5bf9\u4e8e\u7ec4\u7ec7\u7ec4\u4ef6\u548c\u521b\u5efa\u534f\u8c03\u4e00\u81f4\u7684\u5e03\u5c40\u81f3\u5173\u91cd\u8981\u3002\u4e0b\u9762\u8ba9\u6211\u4eec\u9488\u5bf9\u4f7f\u7528 grid \u5e03\u5c40\u7ba1\u7406\u5668\u9047\u5230\u7684\u95ee\u9898\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u751f\u6210\u4e00\u4e2a\u5305\u542b 3 \u4e2a\u6807\u7b7e\u30012 \u4e2a\u6587\u672c\u6846\u548c\u4e00\u4e2a\u6309\u94ae\u7684 gui \u7a97\u53e3\u3002\u5355\u51fb\u6309\u94ae\u65f6\uff0c\u7b2c\u4e09\u4e2a\u6807\u7b7e\u5e94\u663e\u793a\u4e24\u4e2a\u6587\u672c\u6846\u8f93\u5165\u503c\u7684\u548c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<pre>import tkinter as tk\n\n# \u521b\u5efa\u7a97\u53e3\nroot = tk.Tk()\nroot.title(\"Grid \u5e03\u5c40\u793a\u4f8b\")\n\n# \u521b\u5efa\u6807\u7b7e\nlabel1 = tk.Label(root, text=\"\u6807\u7b7e 1\")\nlabel2 = tk.Label(root, text=\"\u6807\u7b7e 2\")\nlabel3 = tk.Label(root, text=\"\u6807\u7b7e 3\")\n\n# \u521b\u5efa\u6587\u672c\u6846\ntx1 = tk.Entry(root)\ntx2 = tk.Entry(root)\n\n# \u521b\u5efa\u6309\u94ae\nbtn = tk.Button(root, text=\"\u6c42\u548c\", command=lambda: label3.configure(text=int(tx1.get()) + int(tx2.get())))\n\n# \u4f7f\u7528 grid \u5e03\u5c40\u7ba1\u7406\u7ec4\u4ef6\nlabel1.grid(row=0, column=0)\nlabel2.grid(row=1, column=0)\ntx1.grid(row=0, column=1)\ntx2.grid(row=1, column=1)\nbtn.grid(row=2, column=1)\nlabel3.grid(row=3, column=1)\n\n# \u7a97\u53e3\u4e3b\u5faa\u73af\nroot.mainloop()<\/pre>\n<p><strong>\u95ee\u9898\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u539f\u59cb\u4ee3\u7801\u4e2d\u5b58\u5728\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5c06 pack \u548c grid \u5e03\u5c40\u7ba1\u7406\u5668\u6df7\u5408\u4f7f\u7528\uff0c\u5bfc\u81f4 python \u65e0\u6cd5\u6b63\u786e\u5904\u7406\u5e03\u5c40\u3002<\/li>\n<li>\u5728 tx1 \u548c tx2 \u8c03\u7528 grid \u65f6\uff0c\u6ca1\u6709\u6307\u5b9a\u884c\u5217\u503c\u3002<\/li>\n<\/ul>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u4f7f\u7528 Grid \u5e03\u5c40\u7ba1\u7406\u5668\u521b\u5efa GUI \u7a97\u53e3\uff1a\u5982\u4f55\u5c06\u4e09\u4e2a\u6807\u7b7e\u3001\u4e24\u4e2a\u6587\u672c\u6846\u548c\u4e00\u4e2a\u6309\u94ae\u5e03\u5c40\u5e76\u5b9e\u73b0\u6c42\u548c\u529f\u80fd\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Grid \u5e03\u5c40\u7ba1\u7406\u5668\u521b\u5efa &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204576","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204576"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204576\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}