Python中turtle.write方法使用說(shuō)明
turtle.write方法使用說(shuō)明
關(guān)于turtle可參見(jiàn) Python的turtle模塊:http://www.dbjr.com.cn/article/238830.htm
turtle.write()方法
在當(dāng)前烏龜位置寫入文本。如:
turtle.write("你好啊", align="center",font=("宋體",10,"normal"))
其中
你好啊 寫入Turtle繪畫屏幕的文字,是字符串格式,要有引號(hào)。
move(可選):在默認(rèn)情況下,move為false。如果move為true,則筆將移動(dòng)到右下角。
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()
運(yùn)行效果如下:
繪制一朵小花的例子
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()
運(yùn)行效果如下:
如何使用turtle.write方法將文字顯示為一個(gè)圓圈?
可近似地將畫筆的運(yùn)動(dòng)軌跡看為一個(gè)正多邊形。
根據(jù)多邊形內(nèi)角和公式:度數(shù)=(邊數(shù)-2)*180,
那么,每次旋轉(zhuǎn)的度數(shù)為:180-度數(shù)/角數(shù)=180-(邊數(shù)-2)*180/邊數(shù)。
易知,邊數(shù)=角數(shù)=文字?jǐn)?shù)
所以每次旋轉(zhuǎn)的度數(shù)為:180-(文字?jǐn)?shù)-2)*180/文字?jǐn)?shù)=360/文字?jǐn)?shù)。
例如
#將文字顯示為一個(gè)圓圈 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()
運(yùn)行效果如下:
總結(jié)
到此這篇關(guān)于Python中turtle.write方法使用說(shuō)明的文章就介紹到這了,更多相關(guān)Python turtle.write方法使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Pandas數(shù)據(jù)分析之批量拆分/合并Excel
怎樣將一個(gè)大的Excel拆分,或者將很多小Excel文件合并?下面這篇文章主要給大家介紹了關(guān)于Pandas數(shù)據(jù)分析之批量拆分/合并Excel的相關(guān)資料,需要的朋友可以參考下2021-09-09python內(nèi)置數(shù)據(jù)類型之列表操作
數(shù)據(jù)類型是一種值的集合以及定義在這種值上的一組操作。這篇文章主要介紹了python內(nèi)置數(shù)據(jù)類型之列表的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11Python多進(jìn)程同步Lock、Semaphore、Event實(shí)例
這篇文章主要介紹了Python多進(jìn)程同步Lock、Semaphore、Event實(shí)例,Lock用來(lái)避免訪問(wèn)沖突、Semaphore用來(lái)控制對(duì)共享資源的訪問(wèn)數(shù)量、Event用來(lái)實(shí)現(xiàn)進(jìn)程間同步通信,需要的朋友可以參考下2014-11-11django之導(dǎo)入并執(zhí)行自定義的函數(shù)模塊圖解
這篇文章主要介紹了django之導(dǎo)入并執(zhí)行自定義的函數(shù)模塊圖解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04Python使用logging模塊實(shí)現(xiàn)打印log到指定文件的方法
這篇文章主要介紹了Python使用logging模塊實(shí)現(xiàn)打印log到指定文件的方法,結(jié)合實(shí)例形式分析了Python logging模塊的原理及相關(guān)日志輸出操作技巧,需要的朋友可以參考下2018-09-09python項(xiàng)目報(bào)錯(cuò):bs4.FeatureNotFound:?Couldn‘t?find?a?tree?bu
這篇文章主要給大家介紹了python項(xiàng)目報(bào)錯(cuò):bs4.FeatureNotFound:?Couldn‘t?find?a?tree?builder?with?the?features?you?requests的解決方式,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09Python執(zhí)行時(shí)間計(jì)算方法以及優(yōu)化總結(jié)
python腳本運(yùn)行時(shí)間遠(yuǎn)遠(yuǎn)大于python腳本中統(tǒng)計(jì)的計(jì)算時(shí)間,所以本文將為大家分享就幾個(gè)Python執(zhí)行時(shí)間計(jì)算方法以及優(yōu)化,感興趣的可以了解一下2022-08-08