{"id":1182025,"date":"2025-01-15T18:58:32","date_gmt":"2025-01-15T10:58:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1182025.html"},"modified":"2025-01-15T18:58:34","modified_gmt":"2025-01-15T10:58:34","slug":"python%e5%a6%82%e4%bd%95%e5%8f%96%e6%b6%88turtle%e7%9a%84%e7%ae%ad%e5%a4%b4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1182025.html","title":{"rendered":"Python\u5982\u4f55\u53d6\u6d88turtle\u7684\u7bad\u5934"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25130152\/201ff657-f7c7-4605-b100-338301d3947b.webp\" alt=\"Python\u5982\u4f55\u53d6\u6d88turtle\u7684\u7bad\u5934\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u53d6\u6d88turtle\u7684\u7bad\u5934\u53ef\u4ee5\u4f7f\u7528hideturtle()\u65b9\u6cd5\u3001\u901a\u8fc7\u4fee\u6539turtle\u7684\u5f62\u72b6\u6765\u5b9e\u73b0<\/strong>\u3002\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u8be6\u7ec6\u63cf\u8ff0hideturtle()\u65b9\u6cd5\u7684\u4f7f\u7528\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u9690\u85cfturtle\u7684\u7bad\u5934\uff0c\u4f7f\u5176\u4e0d\u53ef\u89c1\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001hideturtle()\u65b9\u6cd5\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u5728Python\u7684turtle\u6a21\u5757\u4e2d\uff0c<code>hideturtle()<\/code>\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u6613\u7528\u3002\u5b83\u53ef\u4ee5\u9690\u85cf\u5f53\u524dturtle\u5bf9\u8c61\u7684\u7bad\u5934\uff0c\u4f7f\u5176\u5728\u753b\u5e03\u4e0a\u4e0d\u53ef\u89c1\uff0c\u4f46turtle\u5bf9\u8c61\u4ecd\u7136\u53ef\u4ee5\u7ee7\u7eed\u7ed8\u56fe\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>hideturtle()<\/code>\u65b9\u6cd5\u7684\u6b65\u9aa4\u548c\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165turtle\u6a21\u5757<\/strong>\uff1a\u9996\u5148\u4f60\u9700\u8981\u5bfc\u5165turtle\u6a21\u5757\uff0c\u8fd9\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\u3002<\/li>\n<li><strong>\u521b\u5efaturtle\u5bf9\u8c61<\/strong>\uff1a\u521b\u5efa\u4e00\u4e2aturtle\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u7528\u4e8e\u7ed8\u56fe\u3002<\/li>\n<li><strong>\u4f7f\u7528hideturtle()\u65b9\u6cd5<\/strong>\uff1a\u8c03\u7528turtle\u5bf9\u8c61\u7684<code>hideturtle()<\/code>\u65b9\u6cd5\u6765\u9690\u85cf\u7bad\u5934\u3002<\/li>\n<\/ol>\n<p><p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<h2><strong>\u521b\u5efaturtle\u5bf9\u8c61<\/strong><\/h2>\n<p>t = turtle.Turtle()<\/p>\n<h2><strong>\u8bbe\u7f6eturtle\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>t.shape(&quot;turtle&quot;)<\/p>\n<h2><strong>\u9690\u85cf\u7bad\u5934<\/strong><\/h2>\n<p>t.hideturtle()<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>t.forward(100)<\/p>\n<p>t.left(90)<\/p>\n<p>t.forward(100)<\/p>\n<h2><strong>\u4fdd\u6301\u7a97\u53e3\u6253\u5f00<\/strong><\/h2>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7\u8c03\u7528<code>t.hideturtle()<\/code>\uff0cturtle\u5bf9\u8c61\u7684\u7bad\u5934\u5c06\u88ab\u9690\u85cf\uff0c\u4f46\u5b83\u4ecd\u7136\u53ef\u4ee5\u7ee7\u7eed\u7ed8\u56fe\u3002\u8fd9\u5bf9\u4e8e\u5e0c\u671bturtle\u7ed8\u56fe\u4f46\u4e0d\u5e0c\u671b\u770b\u5230\u7bad\u5934\u7684\u60c5\u51b5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4fee\u6539turtle\u7684\u5f62\u72b6<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u901a\u8fc7\u4fee\u6539turtle\u7684\u5f62\u72b6\u6765\u9690\u85cf\u7bad\u5934\u3002turtle\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u5f62\u72b6\u9009\u9879\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u770b\u8d77\u6765\u4e0d\u592a\u50cf\u7bad\u5934\u7684\u5f62\u72b6\uff0c\u751a\u81f3\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u7a7a\u767d\u7684\u5f62\u72b6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165turtle\u6a21\u5757<\/strong>\uff1a\u5bfc\u5165turtle\u6a21\u5757\u3002<\/li>\n<li><strong>\u521b\u5efaturtle\u5bf9\u8c61<\/strong>\uff1a\u521b\u5efa\u4e00\u4e2aturtle\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u4fee\u6539turtle\u7684\u5f62\u72b6<\/strong>\uff1a\u4f7f\u7528<code>t.shape()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6eturtle\u7684\u5f62\u72b6\u3002<\/li>\n<\/ol>\n<p><p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<h2><strong>\u521b\u5efaturtle\u5bf9\u8c61<\/strong><\/h2>\n<p>t = turtle.Turtle()<\/p>\n<h2><strong>\u8bbe\u7f6eturtle\u7684\u5f62\u72b6\u4e3a&#39;circle&#39;<\/strong><\/h2>\n<p>t.shape(&quot;circle&quot;)<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>t.forward(100)<\/p>\n<p>t.left(90)<\/p>\n<p>t.forward(100)<\/p>\n<h2><strong>\u4fdd\u6301\u7a97\u53e3\u6253\u5f00<\/strong><\/h2>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7\u5c06turtle\u7684\u5f62\u72b6\u8bbe\u7f6e\u4e3a\u201ccircle\u201d\uff0c\u6211\u4eec\u53ef\u4ee5\u6709\u6548\u5730\u9690\u85cf\u7bad\u5934\u3002\u867d\u7136\u5f62\u72b6\u4ecd\u7136\u53ef\u89c1\uff0c\u4f46\u5b83\u4e0d\u518d\u662f\u7bad\u5934\u5f62\u72b6\uff0c\u8fd9\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u66f4\u7b26\u5408\u4f60\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f62\u72b6<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5e0c\u671b\u5b8c\u5168\u81ea\u5b9a\u4e49turtle\u7684\u5f62\u72b6\uff0c\u751a\u81f3\u4f7f\u7528\u4e00\u4e2a\u7a7a\u767d\u7684\u5f62\u72b6\uff0c\u8fd9\u4e5f\u662f\u53ef\u4ee5\u5b9e\u73b0\u7684\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>register_shape()<\/code>\u65b9\u6cd5\u6765\u6ce8\u518c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5f62\u72b6\uff0c\u7136\u540e\u5c06\u5176\u5e94\u7528\u5230turtle\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165turtle\u6a21\u5757<\/strong>\uff1a\u5bfc\u5165turtle\u6a21\u5757\u3002<\/li>\n<li><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684\u5f62\u72b6<\/strong>\uff1a\u4f7f\u7528\u4e00\u4e2a\u7a7a\u767d\u7684GIF\u6587\u4ef6\u6216\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684\u5f62\u72b6\u3002<\/li>\n<li><strong>\u6ce8\u518c\u81ea\u5b9a\u4e49\u5f62\u72b6<\/strong>\uff1a\u4f7f\u7528<code>turtle.register_shape()<\/code>\u65b9\u6cd5\u6ce8\u518c\u81ea\u5b9a\u4e49\u5f62\u72b6\u3002<\/li>\n<li><strong>\u5e94\u7528\u81ea\u5b9a\u4e49\u5f62\u72b6<\/strong>\uff1a\u4f7f\u7528<code>t.shape()<\/code>\u65b9\u6cd5\u5e94\u7528\u81ea\u5b9a\u4e49\u5f62\u72b6\u3002<\/li>\n<\/ol>\n<p><p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u5f62\u72b6<\/strong><\/h2>\n<p>turtle.register_shape(&quot;blank&quot;, ((0,0),))<\/p>\n<h2><strong>\u521b\u5efaturtle\u5bf9\u8c61<\/strong><\/h2>\n<p>t = turtle.Turtle()<\/p>\n<h2><strong>\u8bbe\u7f6eturtle\u7684\u5f62\u72b6\u4e3a&#39;blank&#39;<\/strong><\/h2>\n<p>t.shape(&quot;blank&quot;)<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>t.forward(100)<\/p>\n<p>t.left(90)<\/p>\n<p>t.forward(100)<\/p>\n<h2><strong>\u4fdd\u6301\u7a97\u53e3\u6253\u5f00<\/strong><\/h2>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7\u6ce8\u518c\u548c\u4f7f\u7528\u4e00\u4e2a\u7a7a\u767d\u5f62\u72b6\uff0c\u6211\u4eec\u53ef\u4ee5\u5b8c\u5168\u9690\u85cfturtle\u7684\u7bad\u5934\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Python\u4e2d\u6709\u6548\u5730\u53d6\u6d88turtle\u7684\u7bad\u5934\u3002<strong>\u4f7f\u7528<code>hideturtle()<\/code>\u65b9\u6cd5<\/strong>\u662f\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\uff0c\u800c<strong>\u901a\u8fc7\u4fee\u6539turtle\u7684\u5f62\u72b6<\/strong>\u6216<strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f62\u72b6<\/strong>\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u5f97turtle\u7ed8\u56fe\u66f4\u52a0\u7b26\u5408\u9884\u671f\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528turtle\u5e93\u7ed8\u56fe\u65f6\u9690\u85cf\u7bad\u5934\uff1f<\/strong><br \/>\u5728turtle\u7ed8\u56fe\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>turtle.hideturtle()<\/code>\u51fd\u6570\u6765\u9690\u85cf\u7bad\u5934\u3002\u8fd9\u4e2a\u51fd\u6570\u4f1a\u5c06\u7bad\u5934\u56fe\u6807\u9690\u85cf\u8d77\u6765\uff0c\u4ece\u800c\u8ba9\u7ed8\u5236\u7684\u56fe\u5f62\u770b\u8d77\u6765\u66f4\u52a0\u5e72\u51c0\u3002\u8c03\u7528\u8be5\u51fd\u6570\u540e\uff0c\u518d\u8fdb\u884c\u7ed8\u56fe\u65f6\uff0c\u7bad\u5934\u4e0d\u4f1a\u663e\u793a\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u5728\u7ed8\u5236\u56fe\u5f62\u7684\u8fc7\u7a0b\u4e2d\u4e34\u65f6\u663e\u793a\u548c\u9690\u85cf\u7bad\u5934\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u9700\u8981\u7684\u5730\u65b9\u8c03\u7528<code>turtle.showturtle()<\/code>\u548c<code>turtle.hideturtle()<\/code>\u51fd\u6570\u6765\u63a7\u5236\u7bad\u5934\u7684\u663e\u793a\u4e0e\u9690\u85cf\u3002\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u5f97\u4f60\u53ef\u4ee5\u5728\u7ed8\u5236\u7279\u5b9a\u90e8\u5206\u65f6\u9009\u62e9\u662f\u5426\u663e\u793a\u7bad\u5934\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u7ed8\u56fe\u6548\u679c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u7ed8\u56fe\u5b8c\u6210\u540e\u786e\u4fdd\u7bad\u5934\u4e0d\u518d\u663e\u793a\uff1f<\/strong><br \/>\u5728\u5b8c\u6210\u7ed8\u56fe\u540e\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u7684\u6700\u540e\u8c03\u7528<code>turtle.hideturtle()<\/code>\uff0c\u8fd9\u5c06\u786e\u4fdd\u5728\u7a97\u53e3\u5173\u95ed\u4e4b\u524d\uff0c\u7bad\u5934\u4e0d\u4f1a\u663e\u793a\u3002\u5982\u679c\u5e0c\u671b\u5728\u7a0b\u5e8f\u7ed3\u675f\u540e\u81ea\u52a8\u5173\u95ed\u7a97\u53e3\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>turtle.done()<\/code>\u6765\u7ed3\u675f\u7ed8\u56fe\uff0c\u5e76\u4fdd\u6301\u7a97\u53e3\u6253\u5f00\u72b6\u6001\uff0c\u786e\u4fdd\u7bad\u5934\u4f9d\u7136\u9690\u85cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u53d6\u6d88turtle\u7684\u7bad\u5934\u53ef\u4ee5\u4f7f\u7528hideturtle()\u65b9\u6cd5\u3001\u901a\u8fc7\u4fee\u6539turtle\u7684\u5f62\u72b6\u6765\u5b9e\u73b0\u3002\u5176 [&hellip;]","protected":false},"author":3,"featured_media":1182028,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182025"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1182025"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182025\/revisions"}],"predecessor-version":[{"id":1182030,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182025\/revisions\/1182030"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1182028"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1182025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1182025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1182025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}