python用turtle调整文字位置
发布网友
发布时间:2022-04-19 14:54
我来回答
共1个回答
热心网友
时间:2022-05-22 01:50
一个点上的中心文本(例如在[0,0]处的原点),在X维中,可以使用align=center关键字参数为turtle.write()。要获得沿着Y维对齐,你需要的字体大小稍微调整:
from turtle import Turtle, Screen
FONT_SIZE = 50
FONT = ("Arial", FONT_SIZE, "bold")
yertle = Turtle()
# The turtle starts life in the center of the window
# but let's assume we've been drawing other things
# and now need to return to the center of the window
yertle.penup()
yertle.home()
# By default, the text prints too high unless we roughly
# readjust the baseline, you can confirm text placement
# by doing yertle.dot() after yertle.home() to see center
yertle.sety(-FONT_SIZE/2)
yertle.write("I AM HERE", align="center", font=FONT)
yertle.hideturtle()
screen = Screen()
screen.exitonclick()
不过,如果你不是要开始从中心打印(您的文章是不明确),你可以改变align=center到align=left,或者完全忽略关键字参数align。