turtle.pensize(width=None)
turtle.width(width=None)
Parameters: width – a positive number
设定画笔的粗细.
如果无参数,返回当前笔粗.
画笔(海龟)状态总控:pen
turtle.pen(pen=None, **pendict)
Parameters:
pen – a dictionary with some or all ofthe below listed keys
pendict – oneor more keyword-arguments withthe below listed keysas keywords
turtle.listen(xdummy=None, ydummy=None)
Set focus on TurtleScreen (inorderto collect key-events). Dummy arguments are provided inorderto be able to pass listen() to the onclick method.
在屏幕上设置监听区域.
监听鼠标按键按下:onclick
turtle.onclick(fun, btn=1, add=None)
Parameters:
fun – afunctionwithtwoargumentswhichwillbecalledwiththecoordinatesoftheclickedpointonthecanvasnum – numberofthe mouse-button, defaults to1 (left mouse button)
add – True or False – if True, anew binding will be added, otherwise it will replacea former binding
按下鼠标时,执行绑定的操作.
监听鼠标按键抬起:onrelease
turtle.onrelease(fun, btn=1, add=None)
Parameters:
fun – afunctionwithtwoargumentswhichwillbecalledwiththecoordinatesoftheclickedpointonthecanvasnum – numberofthe mouse-button, defaults to1 (left mouse button)
add – True or False – if True, anew binding will be added, otherwise it will replacea former binding
抬起鼠标按键时,执行绑定的操作.
监听鼠标按键拖动:ondrag
turtle.ondrag(fun, btn=1, add=None)
Parameters:
fun – afunctionwithtwoargumentswhichwillbecalledwiththecoordinatesoftheclickedpointonthecanvasnum – numberofthe mouse-button, defaults to1 (left mouse button)
add – True or False – if True, anew binding will be added, otherwise it will replacea former binding
拖动鼠标按键时,执行绑定的操作.
监听键盘按键:onkey/onkeyrelease/onkeypress
turtle.onkey(fun, key)
turtle.onkeyrelease(fun, key)
turtle.onkeypress(fun, key=None)
Parameters:
fun – a functionwith no arguments or None
key – a string: key (e.g. “a”) orkey-symbol (e.g. “space”)
按下\释放键盘相应按键时,执行操作.
定时操作:ontimer
turtle.ontimer(fun, t=0)
Parameters:
fun – afunctionwithnoarguments
t – anumber >= 0
设定计时器,计时t毫秒后执行fun.
时间循环:mainloop/done
turtle.mainloop()
turtle.done()
Starts event loop - calling Tkinter’s mainloop function. Must be thelast statement in a turtle graphics program. Must not be used if a scriptisrunfrom within IDLE in -n mode (No subprocess) - for interactive use of turtle graphics.
turtle.bgcolor(*args)
Parameters: args – a color stringorthree numbers inthe range 0..colormode ora3-tuple of such numbers
改变屏幕背景色(无参数则返回当前背景色.)
背景图:bgpic
turtle.bgpic(picname=None)
Parameters: picname – astring, name ofa gif-fileor"nopic", or None
设定或返回背景图,picname可以是文件名,如果为’nopic’则删除背景图.
窗口size:screensize
turtle.screensize(canvwidth=None, canvheight=None, bg=None)
Parameters:
canvwidth – positiveinteger, new width of canvas in pixels
canvheight – positiveinteger, new height of canvas in pixels
bg – colorstring or color-tuple, new background color
设定窗口宽\高\背景色.
world坐标:setworldcoordinates
turtle.setworldcoordinates(llx, lly, urx, ury)
Parameters:
llx – anumber, x-coordinate oflower left corner of canvas
lly – anumber, y-coordinate oflower left corner of canvas
urx – anumber, x-coordinate ofupperright corner of canvas
ury – anumber, y-coordinate ofupperright corner of canvas
turtle.setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"])
Parameters:
width – ifaninteger, a size in pixels, ifa float, a fraction ofthe screen; default is 50% of screen
height – ifaninteger, the height in pixels, ifa float, a fraction ofthe screen; default is 75% of screen
startx – if positive, starting position in pixels fromthe left edge ofthe screen, if negative fromtheright edge, if None, center window horizontally
starty – if positive, starting position in pixels fromthe top edge ofthe screen, if negative fromthe bottom edge, if None, center window vertically
classturtle.RawTurtle(canvas)classturtle.RawPen(canvas)
Parameters: canvas – a tkinter.Canvas, a ScrolledCanvas or a TurtleScreen
在给定画布上造一个龟.
默认造龟:Turtle
classturtle.Turtle
RawTurtle的子类,在默认屏幕上造龟.
海龟屏:TurtleScreen
classturtle.TurtleScreen(cv)
Parameters: cv – a tkinter.Canvas
提供一个海龟屏.
屏幕:Screen
classturtle.Screen
海龟屏的子类,添加了上一节里的新功能(bye/title等)
卷屏:ScrolledCanvas
class turtle.ScrolledCanvas(master)
Parameters: master – some Tkinter widget tocontainthe ScrolledCanvas, i.e. a Tkinter-canvas with scrollbars added
Used byclass Screen, which thus automatically provides a ScrolledCanvas as playground forthe turtles.
图形类:Shape
class turtle.Shape(type_, data)
Parameters: type_ – oneofthe strings “polygon”, “image”, “compound”
Shape.addcomponent(poly, fill, outline=None)
Parameters:
poly – a polygon, i.e. a tuple of pairs of numbers
fill – a color the poly will be filled with
outline – a color forthe poly’s outline (if given)
提供了储存图形的数据结构.
type_
data
“polygon”
a polygon-tuple, i.e. a tuple of pairs of coordinates
“image”
an image (in this form only used internally!)
“compound”
None (a compound shape has to be constructed using the addcomponent() method)
向量:Vec2D
class turtle.Vec2D(x, y)
a + b vector addition
a - b vector subtraction
a * b inner product
k * aanda * k multiplication with scalar
abs(a) absolute valueofaa.rotate(angle) rotation
提供了一些二维向量运算.
转换语言:write_docstringdict
turtle.write_docstringdict(filename="turtle_docstringdict")
Parameters: filename – a string, used as filename
Create andwrite docstring-dictionary to a Python scriptwiththegiven filename. This function has to be called explicitly (itisnot used bythe turtle graphics classes). The docstring dictionary will be written tothe Python script filename.py. It is intended to serve as a template for translation ofthe docstrings into different languages.