Python Turtle,在屏幕上用更大的字体绘制文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15141031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:27:39  来源:igfitidea点击:

Python Turtle, draw text with on screen with larger font

pythonturtle-graphics

提问by open source guy

I'm using python turtle's write method to write text on the screen like this:

我正在使用 python 龟的 write 方法在屏幕上写文本,如下所示:

turtle.write("messi fan")

The size of the font is too small. How can I increase the size of font?

字体大小太小。如何增加字体大小?

采纳答案by Andrew Clark

Use the optional fontargument to turtle.write(), from the docs:

使用可选font参数 to turtle.write(), from the docs:

turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))
 Parameters:

  • arg– object to be written to the TurtleScreen
  • move– True/False
  • align– one of the strings “left”, “center” or right”
  • font– a triple (fontname, fontsize, fonttype)

turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))
 参数:

  • arg– 要写入 TurtleScreen 的对象
  • 移动– 真/假
  • align– 字符串“左”、“中”或“右”之一
  • 字体– 三元组(字体名称、字体大小、字体类型)

So you could do something like turtle.write("messi fan", font=("Arial", 16, "normal"))to change the font size to 16 (default is 8).

因此,您可以turtle.write("messi fan", font=("Arial", 16, "normal"))将字体大小更改为 16(默认为 8)。

回答by Lars Tuff

You can also use "bold" and "italic" instead of "normal" here. "Verdana" can be used for fontname..

您也可以在此处使用“粗体”和“斜体”而不是“正常”。“Verdana”可用于字体名称..

But another question is this: How do you set the color of the text You write?

但另一个问题是:你如何设置你写的文本的颜色?

Answer: You use the turtle.color() method or turtle.fillcolor(), like this:

答案:您使用turtle.color() 方法或turtle.fillcolor(),如下所示:

turtle.fillcolor("blue")

or just:

要不就:

turtle.color("orange")

These calls must come before the turtle.write() command..

这些调用必须在turtle.write() 命令之前。

回答by ANDRAOS JIMOH

To add bold, italic and underline, just add the following to the font argument:

要添加粗体、斜体和下划线,只需将以下内容添加到 font 参数中:

font=("Arial", 8, 'normal', 'bold', 'italic', 'underline')

font=("Arial", 8, 'normal', 'bold', 'italic', 'underline')