##初始化turtle:
t = turtle.Turtle() 或者 t = turtle.Pen()
##查询turtle状态
#位置
t.position()

#箭头朝向,箭头朝向按照顺时针或者逆时针偏离的角度描述,具体是顺时针或者逆时针取决于turtle.mode()的值,默认turtle.mode() = standard,表示逆时针方向;logo表示顺时针

t.heading()
#初始状态下箭头向右转20度,t.heading() = 340
t.right(20)
t.left(20)
#向前或向后
t.forward(10)
t.backward(10)
#设置turtle位置
t.goto(x,y) = t.setpos(x,y) = t.setposition(x,y)

t.setx(x)
t.sety(y)
#设置turtle方向,具体方向和turtle.mode相关,默认standard,设置为90度时,箭头指向正北
t.setheading(90)

#turtle回到初始位置和初始方向
t.home()
#turtle回到初始起点,保留角度,清空画布
t.clear()
#turtle重置,回到画布初始状态
t.reset()
#画圆,第一个参数为半径,半径为正值,默认逆时针画圆,半径为负值,顺时针画圆。
#t.circle(-20,90),顺时针,半径20画弧,弧度90
#t.circle(20,90,10),第三个参数指定总共花几步画完,相当于多边形
t.circle(20)
#画点,t.dot(),第一个参数指定圆点半径,第二个参数指定颜色
t.dot()
t.dot(20)
t.dot(20,’blue’)

#撤销动作
t.undo()

#设置turtle移动速度,范围0-10,不加参数返回当前speed
t.speed(10)

#返回x,y坐标位置
t.xcor()
t.ycor()

##turtle到指定位置的距离
t.distance(0,0)

##turtle落下和抬起,抬起时移动不画线;isdown():turtle落下返回真,否则turtle为up状态
t.down()
t.up()
t.isdown()
#设置pen的size,参数为空时返回当前的size
t.pensize(10)

##同时设置多个pen属性
t.pen(**dict)
• “shown”: True/False
• “pendown”: True/False
• “pencolor”: color-string or color-tuple
• “fillcolor”: color-string or color-tuple
• “pensize”: positive number
• “speed”: number in range 0..10
• “resizemode”: “auto” or “user” or “noresize”
• “stretchfactor”: (positive number, positive number)
• “outline”: positive number
• “tilt”: number
• t.pen(fillcolor="black", pencolor="red", pensize=10)

##设置填充颜色,t.color()显示或者设置pencolor和fillcolor
t.fillcolor()
t.color(‘red’,’blue’)

#填充,显示填充是否开启,开始填充,结束填充
t.filling()
t.begin_fill()
t.circle()
t.end_fill()

##显示、隐藏turtle,turtle是否可见
t.hideturtle()
t.showturtle()
t.isvisible()

#设置turtle形状,无参时显示当前turtle形状
t.shape(‘turtle’)

#####################事件处理
#鼠标左键单击事件,fun为绑定函数,需要2个参数,代表点击的位置(x,y),btn指左键单击的次数,只有点击在turtle上才触发绑定。fun=None表示解除绑定
t.onclick(fun,btn=1)
t.onrelease()

#################窗口控制
turtle.bgcolor()
turtle.bgpic() 设置或获取背景图片,只支持gif图片
turtle.clear()
turtle.reset()
turtle.screensize() 窗口尺寸

python模块turtle简单用法的更多相关文章

  1. python制作简单excel统计报表2之操作excel的模块openpyxl简单用法

    python制作简单excel统计报表2之操作excel的模块openpyxl简单用法 # coding=utf-8 from openpyxl import Workbook, load_workb ...

  2. python lambda表达式简单用法【转】

    python lambda表达式简单用法 1.lambda是什么? 看个例子: g = lambda x:x+1 看一下执行的结果: g(1) >>>2 g(2) >>& ...

  3. python模块 __name=='__main__' 用法

    python模块 __name=='__main__' 用法1.ceshi_mod1.pydef test1(): print('111111')def test2(): print('2222')i ...

  4. Python中time和datetime模块的简单用法

    python中与时间相关的一个模块是time模块,datetime模块可以看为是time模块的高级封装. time模块中经常用到的有一下几个方法: time()用来获取时间戳,表示的结果为从1970年 ...

  5. Python#常用的模块和简单用法

    目录 random 随机模块 os 文件夹模块: time 时间模块: matplotlab.pyplot 作图模块 mpl_toolkits.mplot3d 绘制3D图模块 Pygame Reque ...

  6. python optparse模块的简单用法

    # coding = utf-8 from optparse import OptionParser from optparse import OptionGroup usage = 'Usage: ...

  7. Python Lambda 的简单用法

    下面代码简单举例介绍以下 lambda的用法. from functools import reduce #1 python lambda会创建一个函数对象,但不会把这个函数对象赋给一个标识符,而de ...

  8. python,os.path简单用法

    #首先导入os包 import os#引入time模块是因为需要将浮点型的时间转为东八区时间 import time # basename(path),去掉路径名称,单独返回文件名 f = os.pa ...

  9. python 虚拟环境 venv 简单用法

    Python3.3以上的版本通过venv模块原生支持虚拟环境,可以代替Python之前的virtualenv.该venv模块提供了创建轻量级“虚拟环境”,提供与系统Python的隔离支持.每一个虚拟环 ...

随机推荐

  1. 【pytorch】学习笔记(一)-张量

    pytorch入门 什么是pytorch PyTorch 是一个基于 Python 的科学计算包,主要定位两类人群: NumPy 的替代品,可以利用 GPU 的性能进行计算. 深度学习研究平台拥有足够 ...

  2. # 深圳杯D题爬取电视收视率排行榜

    目录 深圳杯D题爬取电视收视率排行榜 站点分析 代码实现 深圳杯D题爬取电视收视率排行榜 站点分析 http://www.tvtv.hk/archives/category/tv 每天的排行版通过静态 ...

  3. python-day37(正式学习)

    前景回顾 抢票系统的代码优化,使用了Lock类 from multiprocessing import Process,Lock import os,time,json with open('user ...

  4. CE修改器使用教程 [入门篇]

    Cheat Engine 一般简称CE,是一个开放源代码的作弊软件,其功能包括:内存扫描.十六进制编辑器.调试工具,Cheat Engine 自身附带了外挂制作工具,可以用它直接生成外挂工具,CE可以 ...

  5. 从尾到头打印列表——牛客剑指offer

    题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 解题思路 思路1: 顺序遍历链表,取出每个结点的数据,插入list中. 由于要求list倒序存储链表中的数据,而我们是顺序取 ...

  6. JavaSSM框架精选50道面试题

    JavaSSM框架精选50道面试题 2019年02月13日 19:04:43 EerhtSedah 阅读数 7760更多 分类专栏: 面试题   版权声明:本文为博主原创文章,遵循CC 4.0 BY- ...

  7. 前端 使用localStorage 和 Cookie相结合的方式跨页面传递参数

    A页面 html代码: 姓名:<input type="text" id="name1"> 年龄:<input type="text ...

  8. ionic 提示 Error: Could not find gradle wrapper within Android SDK.

    Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. 到And ...

  9. luogu题解 P1707 【刷题比赛】矩阵加速递推

    题目链接: https://www.luogu.org/problemnew/show/P1707 分析: 洛谷的一道原创题,对于练习矩阵加速递推非常不错. 首先我们看一下递推式: \(a[k+2]= ...

  10. whistle 前端工具之抓包利器

    一.业务场景 前端本地开发的场景中,我们需要频繁的改动代码,并需要实时看到效果,并且在一些开发场景中,我们需要将特定的请求代理到特定的IP.本地文件等,所以使用fiddler或whistle等本地.真 ...