turtle.write方法使用说明
turtle.write方法使用说明
关于turtle可参见 Python的turtle模块https://blog.csdn.net/cnds123/article/details/108252863
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()
运行效果如下:
turtle.write方法使用说明相关推荐
- python terminator_Python turtle.Terminator方法代碼示例
本文整理匯總了Python中turtle.Terminator方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.Terminator方法的具體用法?Python turtle. ...
- python里turtle.circle什么意思_Python turtle.circle方法代碼示例
本文整理匯總了Python中turtle.circle方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.circle方法的具體用法?Python turtle.circle怎麽 ...
- python color属性_Python turtle.color方法代码示例
本文整理汇总了Python中turtle.color方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.color方法的具体用法?Python turtle.color怎么用?P ...
- PHP中的方形按钮怎么敲,php 魔术方法使用说明
php 魔术方法使用说明 2021-01-23 20:13:0612 PHP5.0后,php面向对象提成更多方法,使得php更加的强大!! 一些在PHP叫魔术方法的函数,在这里介绍一下:其实在一般的应 ...
- python forward(10)什么意思-Python turtle.forward方法代码示例
本文整理汇总了Python中turtle.forward方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.forward方法的具体用法?Python turtle.forwar ...
- python end用法_Python turtle.end_fill方法代码示例
本文整理汇总了Python中turtle.end_fill方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.end_fill方法的具体用法?Python turtle.end_ ...
- python中right是什么意思_Python turtle.right方法代码示例
本文整理汇总了Python中turtle.right方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.right方法的具体用法?Python turtle.right怎么用?P ...
- turtle setuppython_Python turtle.setup方法代碼示例
本文整理匯總了Python中turtle.setup方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.setup方法的具體用法?Python turtle.setup怎麽用?P ...
- python turtle color_Python turtle.color方法代碼示例
本文整理匯總了Python中turtle.color方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.color方法的具體用法?Python turtle.color怎麽用?P ...
最新文章
- io python 读取pdf_实用又好用,6 款 Python 特殊文本格式处理库推荐
- 如何理解Generator
- align=absmiddle 是什么意思
- python中print怎么用_python的print怎么用
- 编程之美2.13子数组的最大乘积
- 洛谷P2587 [ZJOI2008] 泡泡堂
- python tab和空格混用_我的 Python 编码规范
- Angular的@Output与@Input理解
- linux 修改普通用户的 max user process
- 清华霸榜,长沙理工异军突起!第三届 CCF CCSP落下帷幕
- 容器与微服务持续交付
- Android Sqite数据库 9
- 密码保险箱 TBox
- SpringCloud、RabbitMQ、Websocket集群搭建以及集群通信
- 杭州生活小指南-公园卡-寺庙年卡
- proc report过程步
- 王艺瑞浙江大学计算机学院,关于公示2010年(秋)同等学力申请进入论文阶段学员名单的通知...
- 解析java源文件_使用JDT.AST解析java源码
- 推荐9款最佳的编程字体
- J酒店上海中心天之锦餐厅成为全球建筑物中最高的景观餐厅
热门文章
- java生成二维码到文件,java生成二维码转成BASE64
- 单叶双曲面MATLAB编程,在matlab中画函数(x^2+y^2)/9-z^2/4=1的旋转单叶双曲面
- Mysql数据库设计
- Kettle 6.1:Triggering heartbeat signal for ... at every 10 seconds 问题解决
- 原型设计工具——“墨刀”的介绍与基本教程
- 集线器等(概念,工作原理,以及,应用场景)
- IM开发干货分享:网易云信IM客户端的聊天消息全文检索技术实践
- 《庄子·外篇·天运第十四》
- 微信企业号 苹果ios 返回页面不刷新 h5
- 农夫山泉股份有限公司搜索引擎关键词分析