如何從窗口中心開始繪製「turtle」文本?我知道如何創建「烏龜」文本,但我不知道如何將文本居中以使其從窗口中心出現。如何在Python中使用「turtle」模塊居中文本
turtle.write("I AM HERE", font=("Arial", 50, "bold"))
感謝您的幫助,
霍華德
如何從窗口中心開始繪製「turtle」文本?我知道如何創建「烏龜」文本,但我不知道如何將文本居中以使其從窗口中心出現。如何在Python中使用「turtle」模塊居中文本
turtle.write("I AM HERE", font=("Arial", 50, "bold"))
感謝您的幫助,
霍華德
turtle.write(阿根廷,此舉=假align = 「left」,字體=( 「宋體」,8, 「正常「))
參數:
ARG - 對象被寫入TurtleScreen
移動 - 真/假
對齊 - 字符串「左」,「中心」的一個或權」
字體 - 三元字體(fontname,fontsize,fonttype)
一個點上的中心文本(例如在[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
。
[文檔](https://docs.python.org/3/library/turtle.html#turtle.write):您是否嘗試添加'align =「center」'作爲參數? – yeputons