【问题标题】:turtle.write() function not writing in turtle windowturtle.write() 函数不在海龟窗口中写入
【发布时间】:2020-05-02 15:33:01
【问题描述】:

我正在使用 python turtle 编写程序。要在海龟窗口中写入文本,我正在使用以下代码:

def write_text(center_x,center_y,text): # Write text on the Screen
    board.speed(1)
    print("I am here")
    board.penup()
    board.goto(center_x,center_y)
    board.write(text)

但是这段代码并没有在海龟窗口中写任何东西。谁能帮帮我?

【问题讨论】:

    标签: python python-turtle


    【解决方案1】:

    您的write_text() 功能基本没问题。我会寻找您没有看到文本的其他原因。例如。你的笔颜色和背景颜色一样吗?你的屏幕 DPI 是否太密集,看不到海龟默认使用的小字体?

    试试这个函数的简化以及一些调用它的代码:

    from turtle import Screen, Turtle
    
    FONT = ('Arial', 16, 'normal')
    
    def write_text(center_x, center_y, text):
        ''' Write text on the Screen '''
    
        board.penup()
        board.goto(center_x, center_y)
        board.write(text, font=FONT)
    
    board = Turtle()
    
    write_text(100, 100, "You are here.")
    
    screen = Screen()
    screen.exitonclick()
    

    你的海龟窗口中仍然没有任何文字吗?

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 2019-04-23
      • 1970-01-01
      相关资源
      最近更新 更多