窗体函数
t u r t l e . s e t u p ( w i d t h , h e i g h t , s t a r t x , s t a r t y ) \textcolor{red}{turtle.setup(width, height, startx, starty)} turtle.setup(width,height,startx,starty)
设置主窗体的大小和位置
参数 | 描述 |
---|---|
width | 窗口
宽
度
\textcolor{red}{宽度}
宽度 如果值是整数,表示的像素值 如果值是小数,表示窗口宽度与屏幕的比例; |
height | 窗口
高
度
\textcolor{red}{高度}
高度 如果值是整数,表示的像素值 如果值是小数,表示窗口高度与屏幕的比例; |
startx | 窗口
左
侧
\textcolor{red}{左侧}
左侧与屏幕左侧的像素距离 如果值是None 窗口位于屏幕水平中央; |
starty | 窗口
顶
部
\textcolor{red}{顶部}
顶部与屏幕顶部的像素距离 如果值是None 窗口位于屏幕垂直中央; |
画笔状态函数
函数 | 描述 |
---|---|
pendown() |
放
下
\textcolor{red}{放下}
放下画笔 turtle. p u ( ) \textcolor{red}{pu()} pu(), turtle.up() |
penup() |
提
起
\textcolor{red}{提起}
提起画笔 turtle. p d ( ) \textcolor{red}{pd()} pd(), turtle.down() |
pensize(width) | 设置画笔线条的
粗
细
\textcolor{red}{粗细}
粗细为指定大小 无参数输入时返回当前画笔宽度 turtle.width() |
pencolor() | 设置
画
笔
颜
色
\textcolor{red}{画笔颜色}
画笔颜色 无参数输入时返回当前画笔颜色 |
color() | 设置
画
笔
和
填
充
颜
色
\textcolor{red}{画笔和填充颜色}
画笔和填充颜色 无参数输入时返回当前画笔和背景颜色 |
begin_fill() | 图形 填 充 前 \textcolor{red}{填充前} 填充前,调用该方法 |
end_fill() | 图形 填 充 结 束 \textcolor{red}{填充结束} 填充结束 |
filling() | 返回 填 充 状 态 \textcolor{red}{填充状态} 填充状态,True 为填充,False 为未填充 |
clear() | 清 空 \textcolor{red}{清空} 清空当前窗口,但当前画笔的 位 置 不 变 \textcolor{red}{位置不变} 位置不变 |
reset() | 清 空 \textcolor{red}{清空} 清空当前窗口,并 重 置 位 置 \textcolor{red}{重置位置} 重置位置等状态为默认值 |
screensize() | 设置
画
布
的
宽
度
、
高
度
和
背
景
颜
色
\textcolor{red}{画布的宽度、高度和背景颜色}
画布的宽度、高度和背景颜色 无参数输入时返回当前画布窗口的宽度和高度 |
hideturtle() | 隐 藏 \textcolor{red}{隐藏} 隐藏画笔的 turtle 形状 |
showturtle() | 显 示 \textcolor{red}{显示} 显示画笔的 turtle 形状 |
isvisible() | 如果 turtle 可见,则返回 True |
write(str,font) |
输
出
字
符
\textcolor{red}{输出字符}
输出字符 font=(<字体名称>,<字体尺寸>,<字体类型>) |
画笔运动函数
函数 | 描述 |
---|---|
forward() | 沿着当前方向
前
进
指
定
距
离
\textcolor{red}{前进指定距离}
前进指定距离 turtle. f d \textcolor{red}{fd} fd(distance) |
backward() | 沿着当前相反方向
后
退
指
定
距
离
\textcolor{red}{后退指定距离}
后退指定距离 turtle. b k \textcolor{red}{bk} bk(distance) |
right(angle) | 向 右 旋 转 \textcolor{red}{右旋转} 右旋转 angle 角度 |
left(angle) | 向 左 旋 转 \textcolor{red}{左旋转} 左旋转 angle 角度 |
goto(x,y) | 移动到绝对坐标 ( x , y ) \textcolor{red}{(x,y)} (x,y)处 |
setx( ) | 将当前 x 轴 \textcolor{red}{x 轴} x轴 移动到指定位置 |
sety( ) | 将当前 y 轴 \textcolor{red}{ y 轴} y轴 移动到指定位置 |
setheading(angle) | 设置
当
前
朝
向
为
a
n
g
l
e
角
度
\textcolor{red}{当前朝向为 angle 角度}
当前朝向为angle角度 turtle. s e t h \textcolor{red}{seth} seth(to_angle) |
home() | 设置当前画笔位置为 原 点 \textcolor{red}{原点} 原点,朝向东。 |
circle(radius,e) | 绘制一个指定半径 r 和角度 e 的圆或
弧
形
\textcolor{red}{弧形}
弧形 circle(radius,steps=<边数>) x 边 形 \textcolor{red}{x 边形} x边形 |
dot(r,color) | 绘制一个指定半径 r 和颜色 color 的 有 色 圆 点 \textcolor{red}{有色圆点} 有色圆点 |
undo() | 撤 销 \textcolor{red}{撤销} 撤销画笔最后一步动作 |
speed() | 设置画笔的绘制 速 度 \textcolor{red}{速度} 速度,参数为 0-10 之间 |