{"id":931,"date":"2025-01-12T10:39:27","date_gmt":"2025-01-12T02:39:27","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=931"},"modified":"2025-01-12T10:39:27","modified_gmt":"2025-01-12T02:39:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aa%e6%97%a0%e6%b3%95%e6%8b%92%e7%bb%9d%e5%85%8d%e8%b4%b9%e5%8a%a0%e7%8f%ad%e7%9a%84%e9%a1%b5%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/12\/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aa%e6%97%a0%e6%b3%95%e6%8b%92%e7%bb%9d%e5%85%8d%e8%b4%b9%e5%8a%a0%e7%8f%ad%e7%9a%84%e9%a1%b5%e9%9d%a2\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Python\u5236\u4f5c\u4e00\u4e2a\u65e0\u6cd5\u62d2\u7edd\u514d\u8d39\u52a0\u73ed\u7684\u9875\u9762"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u4f7f\u7528 Python \u6765\u521b\u5efa\u4e00\u4e2a\u754c\u9762\uff0c\u8ba9\u7528\u6237\u5728\u9009\u62e9\u65f6\u65e0\u6cd5\u62d2\u7edd\u514d\u8d39\u52a0\u73ed\u7684\u9009\u9879\uff08\u5373\u7528\u6237\u53ea\u80fd\u9009\u62e9\u201c\u613f\u610f\u201d\u800c\u65e0\u6cd5\u9009\u62e9\u201c\u4e0d\u613f\u610f\u201d\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>tkinter<\/code> \u5e93\u6765\u5b9e\u73b0\u3002<code>tkinter<\/code> \u662f Python \u6807\u51c6\u5e93\u4e2d\u7528\u4e8e\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u6a21\u5757\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u793a\u4f8b<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import tkinter as tk\nfrom tkinter import messagebox\n\ndef on_select(option):\n    if option == \"\u4e0d\u613f\u610f\":\n        # \u901a\u8fc7\u8bbe\u7f6e\u9009\u9879\u56de\u5230\u201c\u613f\u610f\u201d\uff0c\u786e\u4fdd\u7528\u6237\u65e0\u6cd5\u9009\u62e9\u201c\u4e0d\u613f\u610f\u201d\n        messagebox.showwarning(\"\u8b66\u544a\", \"\u4f60\u65e0\u6cd5\u9009\u62e9\u4e0d\u613f\u610f\uff01\")\n        willing_button.select()  # \u81ea\u52a8\u9009\u62e9\u201c\u613f\u610f\u201d\u6309\u94ae\n\n# \u521b\u5efa\u4e3b\u7a97\u53e3\nroot = tk.Tk()\nroot.title(\"\u514d\u8d39\u52a0\u73ed\u9009\u62e9\")\nroot.geometry(\"300x150\")\n\n# \u6dfb\u52a0\u6807\u7b7e\nlabel = tk.Label(root, text=\"\u4f60\u613f\u610f\u514d\u8d39\u52a0\u73ed\u5417\uff1f\", font=(\"Arial\", 14))\nlabel.pack(pady=10)\n\n# \u521b\u5efa\u4e00\u4e2a\u5355\u9009\u6846\nwilling_button = tk.Radiobutton(root, text=\"\u613f\u610f\", value=\"\u613f\u610f\", font=(\"Arial\", 12))\nwilling_button.pack(anchor=\"w\", padx=20)\n\nunwilling_button = tk.Radiobutton(root, text=\"\u4e0d\u613f\u610f\", value=\"\u4e0d\u613f\u610f\", font=(\"Arial\", 12),\n                                  command=lambda: on_select(\"\u4e0d\u613f\u610f\"))\nunwilling_button.pack(anchor=\"w\", padx=20)\n\n# \u9ed8\u8ba4\u9009\u62e9\u201c\u613f\u610f\u201d\u6309\u94ae\nwilling_button.select()\n\n# \u542f\u52a8\u4e3b\u5faa\u73af\nroot.mainloop()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u89e3\u91ca<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7a97\u53e3\u521b\u5efa<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>tk.Tk()<\/code> \u521b\u5efa\u4e3b\u7a97\u53e3\uff0c\u8bbe\u7f6e\u7a97\u53e3\u6807\u9898\u548c\u5927\u5c0f\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6807\u7b7e<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Label<\/code> \u7528\u4e8e\u663e\u793a\u95ee\u9898\uff1a\u201c\u4f60\u613f\u610f\u514d\u8d39\u52a0\u73ed\u5417\uff1f\u201d\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5355\u9009\u6309\u94ae<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Radiobutton<\/code> \u521b\u5efa\u4e24\u4e2a\u9009\u9879\uff1a\u201c\u613f\u610f\u201d\u548c\u201c\u4e0d\u613f\u610f\u201d\u3002<\/li>\n\n\n\n<li>\u4e3a\u6bcf\u4e2a\u6309\u94ae\u6307\u5b9a\u4e86\u4e00\u4e2a\u503c\u548c\u5b57\u4f53\u6837\u5f0f\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u903b\u8f91\u5904\u7406<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6211\u4eec\u901a\u8fc7 <code>on_select<\/code> \u51fd\u6570\u6355\u83b7\u70b9\u51fb\u4e86\u201c\u4e0d\u613f\u610f\u201d\u7684\u4e8b\u4ef6\u3002<\/li>\n\n\n\n<li>\u5728\u8be5\u51fd\u6570\u5185\uff0c<code>messagebox.showwarning()<\/code> \u4f1a\u5f39\u51fa\u8b66\u544a\u6846\uff0c\u63d0\u793a\u7528\u6237\u201c\u4f60\u65e0\u6cd5\u9009\u62e9\u4e0d\u613f\u610f\uff01\u201d\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>willing_button.select()<\/code> \u5f3a\u5236\u5c06\u9009\u9879\u8bbe\u7f6e\u4e3a\u201c\u613f\u610f\u201d\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9ed8\u8ba4\u9009\u4e2d\u201c\u613f\u610f\u201d<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u7a97\u53e3\u542f\u52a8\u65f6\uff0c\u81ea\u52a8\u9009\u4e2d\u201c\u613f\u610f\u201d\u6309\u94ae\uff0c\u786e\u4fdd\u7528\u6237\u5728\u542f\u52a8\u65f6\u6ca1\u6709\u9009\u62e9\u201c\u62d2\u7edd\u201d\u9009\u9879\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u8fd0\u884c\u6548\u679c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u6b64\u7a0b\u5e8f\u65f6\uff0c\u754c\u9762\u4e0a\u4f1a\u51fa\u73b0\u4e00\u4e2a\u7a97\u53e3\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u613f\u610f\u514d\u8d39\u52a0\u73ed\u3002\u7528\u6237\u53ea\u80fd\u9009\u62e9\u201c\u613f\u610f\u201d\uff0c\u5e76\u4e14\u5982\u679c\u5c1d\u8bd5\u9009\u62e9\u201c\u4e0d\u613f\u610f\u201d\uff0c\u4f1a\u5f39\u51fa\u8b66\u544a\u6d88\u606f\u6846\uff0c\u5f3a\u5236\u9009\u62e9\u201c\u613f\u610f\u201d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c0f\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u4f7f\u7528 <code>tkinter<\/code>\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u8fd9\u6837\u7684\u56fe\u5f62\u754c\u9762\uff0c\u5e76\u901a\u8fc7\u903b\u8f91\u63a7\u5236\u6765\u9650\u5236\u7528\u6237\u7684\u9009\u62e9\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u7528\u6765\u5f3a\u5236\u7528\u6237\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u6216\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u60f3\u4f7f\u7528 Python \u6765\u521b\u5efa\u4e00\u4e2a\u754c\u9762\uff0c\u8ba9\u7528\u6237\u5728\u9009\u62e9\u65f6\u65e0\u6cd5\u62d2\u7edd\u514d\u8d39\u52a0\u73ed\u7684\u9009\u9879\uff08\u5373\u7528\u6237\u53ea\u80fd\u9009\u62e9\u201c\u613f\u610f\u201d\u800c\u65e0\u6cd5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-931","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=931"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/931\/revisions"}],"predecessor-version":[{"id":932,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/931\/revisions\/932"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}