Python学习——Python海龟制图中的文字

可以用海龟的write方法显示文字,代码如下:

import turtle as t

t.setup(600, 400)
t.write("人生苦短,我用Python", font=("微软雅黑", 14, "normal"))  #fonttype有normal, bold, italic, underline

t.penup()
t.right(90)
t.fd(50)
t.pendown()
t.pencolor("purple")
t.write("This is a test", font=("Arial", 14, "bold"))  #fonttype可以自由组合,如"bold italic"

t.penup()
t.fd(50)
t.pendown()
t.pencolor("blue")
t.write("This is a test2", font=("Times New Roman", 14, "bold underline"))

t.done()

效果如下:

Python学习——Python海龟制图中的文字_第1张图片

 

 

此外,还可以参考以下博客:

Python学习笔记(七):Turtle绘图(3)[write()函数]

https://blog.csdn.net/Commander_WingT/article/details/88748970

 

 

你可能感兴趣的:(python)