这是我n年以前整理的python海龟turtle库的格式(有那么一点点多 常用的都有)

也就300来行吧。。。。格式如下👇👇👇

画布
import turtle
turtle.screensize(canvwidth=None,canvheight=None,bg=None)

import turtle
turtle.setup(width=None,height=None,startx=None,starty=None)

import turtle as t
t.screensize(canvwidth=None,canvheight=None,bg=None)

import turtle as t
t.setup(width=None,height=None,startx=None,starty=None)

canvwidth:宽(单位像素)
canvheight:高(单位像素)
bg:背景颜色(默认白色)
width:宽度(占屏幕的比例)
height:高度(占屏幕的比例)
startx:左上角顶点坐标(默认在屏幕中间)
starty:左上角顶点坐标(默认在屏幕中间)

画布颜色
turtle.Screen().bgcolor("color")

t.Screen().bgcolor("color")

turtle.colormode(255)
turtle.Screen().bgcolor(R,G,B)

t.colormode(255)
t.Screen().bgcolor(R,G,B)

bgcolor:背景颜色

让海龟前进
turtle.forward(distance)

t.forward(distance)

distance:海龟前进的距离

让海龟后退
turtle.backward(distance)

t.backward(distance)

distance:海龟后退的距离

让海龟转弯
turtle.right(degree)
turtle.left(degree)

t.right(degree)
t.left(degree)

right:右转
left:左转
degree:角度

三种移动代码
turtle.goto(x,y=None)
turtle.setposition(x,y=None)
turtle.setpos(x,y=None)

t.goto(x,y=None)
t.setposition(x,y=None)
t.setpos(x,y=None)

goto:去;到
x:x坐标
y:y坐标
setposition:置位位置; 设置位置
setpos:设置位置

让海龟平移
turtle.setx(x)
turtle.sety(y)

setx:设置x坐标为……
sety:设置y坐标为……
x:x坐标
y:y坐标

改变指向
turtle.setheading(to_angle)

to_angle:角度

移动速度
turtle.speed(speed=None)

t.speed(speed=None)

speed:移动速度(海龟移动速度分位10个档,即1-10。1最慢,10最快。填入的参数大于10或小于0.5,速度会被自动设为0。0的速度和10一样,为最快速度,这个速度下几乎看不到海龟的移动过程)

消除
turtle.undo()

t.undo()

undo:撤销

清屏
turtle.clear()

t.clear()

clear:清屏

回到原点
turtle.home()

t.home()

home:原点

调查海龟的具体位置
turtle.position()

t.position()

position:位置

调查海龟的x坐标
turtle.xcor()

t.xcor()

xcor:海龟的x坐标

调查海龟的y坐标
turtle.ycor()

t.ycor()

xcor:海龟的y坐标

调查海龟面朝的方向
turtle.heading()

t.heading()

heading:方向

提笔
turtle.penup()

t.penup()

penup:提笔

落笔
turtle.pendown()

t.pendown()

pendown:落笔

线条粗细
turtle.pensize(width=None)

t.pensize(width=None)

width:宽度

如何画圆
turtle.circle(r,extent=None,steps=None)

t.circle(r,extent=None,steps=None)

r:半径
extent:角度
steps:步数

改变画笔颜色
turtle.pencolor(*args)

t.pencolor(*args)

turtle.colormode(255)
turtle.pencolor(r,g,b)

t.colormode(255)
t.pencolor(r,g,b)

*args:颜色(字符串)(单词)
r:红色
g:绿色
b:蓝色

填充颜色
turtle.fillcolor(*args)
turtle.begin_fill()
……
turtle.end_fill()

t.fillcolor(*args)
t.begin_fill()
……
t.end_fill()

turtle.colormode(255)
turtle.fillcolor(r,g,b)
turtle.begin_fill()
……
turtle.end_fill()

t.colormode(255)
t.fillcolor(r,g,b)
t.begin_fill()
……
t.end_fill()

*args:颜色(字符串)(单词)
r:红色
g:绿色
b:蓝色
begin_fill:开始填充
end_fill:结束填充

同时设置画笔颜色与填充颜色
turtle.color("pencolor","fillcolor")

t.color("pencolor","fillcolor")

pencolor:画笔颜色
fillcolor:填充颜色

形状设置
turtle.shape("turtle")

t.shape("turtle")

turtle.shape("classic")

t.shape("classic")

turtle.shape("arrow")

t.shape("arrow")

turtle.shape("circle")

t.shape("circle")

turtle.shape("square")

t.shape("square")

turtle.shape("triangle")

t.shape("triangle")
turtle:海龟
arrow:箭头
circle:圆
classic:经典
square:正方形
triangle:三角形
shape:形状

颜色设置
turtle.colormode(255)
turtle.color(R,G,B)

turtle.color(color)

t.colormode(255)
t.color(R,G,B)

t.color("color")

R:红色
G:绿色
B:蓝色
color:颜色(字符串)(单词)

海龟的大小设置
turtle.turtlesize(a,b,c)

t.turtlesize(a,b,c)

turtlesize:乌龟大小
a:海龟的宽度(上下距离)
b:海龟的左右(左右距离)
c:海龟的轮廓宽度

重置海龟大小
turtle.resizemode("auto")

t.resizemode("auto")

resizemode:重置模型
auto:自动(变回原来大小)

海龟的显示
turtle.showturtle()

turtle.showturtle()

showturtle:海龟显示

海龟的隐藏
turtle.hideturtle()

t.hideturtle()

hideturtle:海龟隐藏

标题设置
turtle.title("titlestring")

t.title("titlestring")

titlestring:设置标题

关闭窗口
turtle.bye()

t.bye()

bye:再见

这是我自己整理的 借用吱一声

turtle事例看我链接:海龟turtle库案例(会更新) – laolibuhuifei’s blog

评论

  1. 周黑鸭
    Windows Edge 144.0.0.0
    1 月前
    2026-2-03 19:16:24

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇