{"id":204654,"date":"2025-05-29T09:17:46","date_gmt":"2025-05-29T01:17:46","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204654\/"},"modified":"2025-05-29T09:17:46","modified_gmt":"2025-05-29T01:17:46","slug":"python-%e8%87%aa%e5%ae%9a%e4%b9%89%e7%b1%bb%e5%ae%9e%e4%be%8b%e5%8c%96%e5%a4%b1%e8%b4%a5%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88-button-%e7%b1%bb%e6%97%a0%e6%b3%95%e5%88%9b%e5%bb%ba%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204654\/","title":{"rendered":"Python \u81ea\u5b9a\u4e49\u7c7b\u5b9e\u4f8b\u5316\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 Button \u7c7b\u65e0\u6cd5\u521b\u5efa\u5b9e\u4f8b\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u81ea\u5b9a\u4e49\u7c7b\u5b9e\u4f8b\u5316\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 Button \u7c7b\u65e0\u6cd5\u521b\u5efa\u5b9e\u4f8b\uff1f<\/h1>\n<p>\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/1731405808673327f0b6d18.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u81ea\u5b9a\u4e49\u7c7b\u5b9e\u4f8b\u5316\u5931\u8d25<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u5c1d\u8bd5\u5b9e\u4f8b\u5316\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b button \u65f6\uff0c\u9047\u5230 &#8220;\u65e0\u6cd5\u521b\u5efa\u5b9e\u4f8b&#8221; \u7684\u9519\u8bef\u3002\u4ee5\u4e0b\u4ee3\u7801\u6765\u81ea button_game \u5305\uff1a<\/p>\n<pre>import pygame\nfrom button_game.setting import Settings\nfrom button_game import game_functions as gf\nfrom button_game.button import Button\n\ndef run_game():\n    pygame.init()\n    button_setting = Settings()\n\n    screen = pygame.display.set_mode(button_setting.screen_width, button_setting.screen_height)\n    screen.display.set_caption(\"\u6309\u952e\")\n    button = Button(button_setting, screen)  # \u8fd9\u91cc\u62a5\u9519\n\nwhile True:\n    gf.check_events(button)<\/pre>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u5173\u952e\u5728\u4e8e\u786e\u4fdd __init__.py \u6587\u4ef6\u5b58\u5728\u4e8e button_game \u76ee\u5f55\u4e2d\u3002__init__.py \u6587\u4ef6\u544a\u8bc9 python \u8be5\u76ee\u5f55\u662f\u4e00\u4e2a\u5305\uff0c\u5141\u8bb8\u4ece\u5305\u4e2d\u5bfc\u5165\u6a21\u5757\u3002<\/p>\n<p>\u8981\u5728 button_game \u76ee\u5f55\u4e2d\u521b\u5efa __init__.py \u6587\u4ef6\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\u3002<\/li>\n<li>\u5728 button_game \u76ee\u5f55\u4e0b\u521b\u5efa\u65b0\u6587\u4ef6\u3002<\/li>\n<li>\u5c06\u6587\u4ef6\u547d\u540d\u4e3a __init__.py\uff08\u786e\u4fdd\u6587\u4ef6\u540d\u4e2d\u5305\u542b\u4e24\u4e2a\u4e0b\u5212\u7ebf\uff09\u3002<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p>\u5728\u521b\u5efa\u4e00\u4e2a __init__.py \u6587\u4ef6\u540e\uff0c\u5c31\u53ef\u4ee5\u6210\u529f\u5bfc\u5165 button \u7c7b\u5e76\u5b9e\u4f8b\u5316\u5b83\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aPython \u81ea\u5b9a\u4e49\u7c7b\u5b9e\u4f8b\u5316\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 Button \u7c7b\u65e0\u6cd5\u521b\u5efa\u5b9e\u4f8b\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u81ea\u5b9a\u4e49\u7c7b\u5b9e\u4f8b\u5316\u5931\u8d25&#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-204654","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204654","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=204654"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204654\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}