2017-02-16 2205 views
0

如何从窗口中心开始绘制“turtle”文本?我知道如何创建“乌龟”文本,但我不知道如何将文本居中以使其从窗口中心出现。如何在Python中使用“turtle”模块居中文本

turtle.write("I AM HERE", font=("Arial", 50, "bold")) 

感谢您的帮助,

霍华德

+0

[文档](https://docs.python.org/3/library/turtle.html#turtle.write):您是否尝试添加'align =“center”'作为参数? – yeputons

回答

0

turtle.write(阿根廷,此举=假align = “left”,字体=( “宋体”,8, “正常“))

参数:

ARG - 对象被写入TurtleScreen

移动 - 真/假

对齐 - 字符串“左”,“中心”的一个或权”

字体 - 三元字体(fontname,fontsize,fonttype)

0

一个点上的中心文本(例如在[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=centeralign=left,或者完全忽略关键字参数align

+0

非常感谢你..它的工作! – howard

+0

非常感谢你 – howard