python turtle module 总结一(基本)

python turtle module 总结一(基本)

一、screen

screen = turtle.Screen()  # screen object

screen 对象

screen.bgcolor()  # 背景颜色
# RGB 或者 字符串

设置背景颜色

screen.clear()

清屏

screen.rsset()

重置

screen.screensize(int, int)  # 默认为:(400, 300)

turtle.screensize(canvwidth=None, canvheight=None, bg=None)

画布大小

screen.window_width()
screen.window_height()

屏幕大小

turtle.bye()

关闭海龟绘图窗口

screen.title(string)

窗口标题

二、turtle

tur = turtle.Turtle()

创建turtle对象

tur.forward(int or float)

向前

tur.back(int or float)

后退

tur.right(int or float)  # 角度为度,不是弧度

右转(顺时针旋转)

tur.left(int or float)

左转(逆时针旋转)

tur.goto(int or float, int or float)

到某一个指定的位置处

tur.setx(int or float)
tur.sety(int or float)

tur.setx():设置x坐标
tur.sety():设置y坐标

tur.setheading(int or float)
print(tur.heading())

设置指向并打印

指向信息

tur.home()

返回原点

turtle.circle(radius, extent=None, steps=None)
# 半径为正:顺时针
# 半径为负:逆时针

画圆
举例如下:

在这里插入图片描述

tur.dot(intint>=1, string or rgb)

画点

tur.undo()
# tur.undo() 无参数

撤销上一个动作
(用循环可以实现撤销多个动作)

tur.speed(int)
# 1 <= int <= 10

设置turtle对象的移动速度

tur.position()
tur.xcor()
tur.ycor()
turtle.towards(x, y=None)
# x -- 一个数值或数值对/矢量,或一个海龟实例
# y -- 一个数值——如果 x 是一个数值,否则为 None
tur.heading()

位置, x坐标, y坐标, 目标方向, 朝向

tur.distance(int or float, int or float)

到某点的距离

tur.up()
tur.down()

抬起笔, 落下笔

tur.pensize(int)

设置画笔大小

tur.pencolor(string or RGB)

设置画笔颜色

tur.fillcolor(string or RGB)
# 举例如下:
tur.fillcolor('red')
tur.begin_fill()
tur.circle(90)
tur.end_fill()

设置填充颜色并进行填充

tur.reset()

重置

tur.clear()

清空
注意tur.reset()与tur.clear()的区别

tur.write(string)
turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))  
# string 就是后一个的 arg 
turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))
参数
arg -- 要书写到 TurtleScreen 的对象

move -- True/False

align -- 字符串 "left", "center""right"

font -- 一个三元组 (fontname, fontsize, fonttype)

书写文字

tur.hideturtle()
tur.showturtle()
tur.isvisible()

隐藏、显示turtle,查看turtle是否可见

tur.shape()
# "arrow", "turtle", "circle", "square", "triangle", "classic"

turtle的形状

turtle.shapesize(stretch_wid=None, stretch_len=None, outline=None)

turtle的形状大小

猜你喜欢

转载自blog.csdn.net/m0_54218263/article/details/114188395