【问题标题】:Turtle function draws a line even after using penup when I label coordinate axis当我标记坐标轴时,即使在使用 penup 之后,Turtle 函数也会画一条线
【发布时间】:2021-11-22 06:19:59
【问题描述】:

我正在尝试使用 penup 和 pendown 函数来防止海龟在移动位置以分别标记 x 轴和 y 轴上的坐标点时画线。但令我惊讶的是,它仍然划清界限。在出现错误的代码行下方!

        alex.penup()
        alex.setpos(index-10,300-20) #Line appears even after lineup
        alex.pendown()
        alex.write(label,font=("Arial", 10, "normal"))

以下是源代码-https://replit.com/join/gtywdtyqia-uditswaroopa

Current Output

【问题讨论】:

  • 如答案中所述 - 没有登录就无法访问源代码。尝试并分享一个完全演示您遇到的问题的最小代码示例。但除此之外,这是个好问题。

标签: python turtle-graphics python-turtle


【解决方案1】:

您在 replit.com 上的源代码需要登录,因此人们可能无法检查它——请将其包含在您的问题中。

您显示的代码看起来不错,但它是笔移动到要写入标签的位置。我怀疑当海龟写完标签返回时,线条可能会被画出来,即你没有显示的下一行代码:

    alex.penup()
    alex.setpos(index-10,300-20)
    alex.pendown()
    alex.write(label,font=("Arial", 10, "normal"))
    alex.goto(index,300)

虽然你可以用另一个penup() 包裹这个goto(),但write() 方法不需要放下笔,所以在你写所有标签的整个过程中试着把笔放在上面。

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    相关资源
    最近更新 更多