Python中turtle.write方法使用說明
turtle.write方法使用說明
關于turtle可參見 Python的turtle模塊:http://m.fzitv.net/article/238830.htm
turtle.write()方法
在當前烏龜位置寫入文本。如:
turtle.write("你好啊", align="center",font=("宋體",10,"normal"))其中
你好啊 寫入Turtle繪畫屏幕的文字,是字符串格式,要有引號。
move(可選):在默認情況下,move為false。如果move為true,則筆將移動到右下角。
align(可選):可取值是left即左、center即中、right即右之一,是字符串格式。
font(可選):字體三元組(fontname、fontsize、fonttype),fontname即字體名稱,fontsize即字體大小,fonttype即字體類型如:normal、bold、italic。。
例子
import turtle
info = "你輸入的文字"
turtle.penup()
turtle.fd(-300)
turtle.pencolor('red')
for i in info:
turtle.write(i, font=('宋體',40,'normal'))
turtle.fd(60)
turtle.hideturtle()運行效果如下:

繪制一朵小花的例子
import turtle as t
t.penup()
t.fd(-200)
t.write("一朵小花\n", align="right", font=("楷體", 16, "bold"))
def draw_leaf():
for i in range(2):
for j in range(15):
t.forward(5)
t.right(6)
t.right(90)
t.goto(0,-150)
t.left(90)
t.down()
t.forward(50)
t.fillcolor("green")
t.begin_fill()
draw_leaf()
t.end_fill()
t.forward(50)
t.right(270)
t.fillcolor("green")
t.begin_fill()
draw_leaf()
t.end_fill()
t.right(90)
t.forward(130)
t.fillcolor("red")
t.begin_fill()
for i in range(6):
draw_leaf()
t.right(60)
t.end_fill()
t.done()運行效果如下:

如何使用turtle.write方法將文字顯示為一個圓圈?
可近似地將畫筆的運動軌跡看為一個正多邊形。
根據多邊形內角和公式:度數=(邊數-2)*180,
那么,每次旋轉的度數為:180-度數/角數=180-(邊數-2)*180/邊數。
易知,邊數=角數=文字數
所以每次旋轉的度數為:180-(文字數-2)*180/文字數=360/文字數。
例如
#將文字顯示為一個圓圈
import turtle
text="你要顯示的文字"
turtle.pu()
x=len(text)
for i in text:
turtle.write(i,font='consolas')
turtle.rt(360/x)
turtle.pu()
turtle.fd(30)
turtle.hideturtle()運行效果如下:

總結
到此這篇關于Python中turtle.write方法使用說明的文章就介紹到這了,更多相關Python turtle.write方法使用內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python 利用jieba.analyse進行 關鍵詞提取
這篇文章主要介紹了python 利用jieba.analyse進行關鍵詞提取的方法,幫助大家更好的利用python,感興趣的朋友可以了解下2020-12-12

