You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Turtle绘图中海龟箭头无法隐藏问题求助

Python Turtle海龟箭头无法隐藏的问题修复

你的代码核心问题是混淆了全局海龟实例和自定义的bob海龟实例:你一直调用turtle.hideturtle(),但这个方法作用于Turtle库默认创建的全局海龟,而你绘图用的是自己定义的bob实例,所以这个操作对bob完全无效,导致箭头始终可见。

修复方法

直接对bob调用hideturtle()即可,不需要把海龟移到屏幕外。修改后的完整代码如下:

import turtle
bob = turtle.Turtle()
scr = turtle.getscreen()
scr.bgcolor("#85B14E")
bob.speed(0)  
bob.color("yellow")
turtle.tracer(0)  
bob.hideturtle()  # 针对自定义的bob实例隐藏海龟

def flower():
    for i in range(21):
        bob.forward(20)
        bob.left(163)

def flowers():
    for i in range(49):
        bob.penup()
        bob.goto(0, 0) 
        bob.forward(150)
        bob.pendown()
        flower()
        bob.penup()
        bob.goto(0, 0) 
        bob.left(8)

flowers()
turtle.update()    
turtle.done()

关键修改点

  1. 把原代码中的turtle.hideturtle()替换为bob.hideturtle(),直接对绘图用的实例操作。
  2. 移除了末尾多余的bob.goto(1000,10000),隐藏海龟后无需此操作。
  3. 删除了重复的无效turtle.hideturtle()调用,初始化后调用一次bob.hideturtle()即可生效。

内容的提问来源于stack exchange,提问作者Smilingpotato404

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 10:17:08