python module turtle simple usage

## Initialization turtle:
T = turtle.Turtle () or turtle.Pen = T ()
## turtle status query
# position
t.position ()

# Arrow direction, the arrow direction clockwise or counterclockwise described in terms of an angle deviation, clockwise or counterclockwise depending on the particular value turtle.mode (), the default turtle.mode () = standard, represents the counterclockwise direction; logo represents clockwise

t.heading ()
arrow 20 degrees right turn at an initial state #, t.heading () = 340.
t.right (20)
t.left (20)
# forward or backward
t.forward (10)
t.backward (10)
# set turtle position
t.goto (x, y) = t.setpos (x, y) = t.setposition (x, y)

t.setx (X)
t.sety (Y)
# set turtle direction, particularly the direction and turtle.mode related, Standard default, when set to 90 degrees, the arrow pointing to north
t.setheading (90)

#turtle back to the initial position and the initial direction
t.home ()
#turtle returned to the initial starting point, retention angle, empty canvas
t.clear ()
#turtle reset back to the initial state canvas
t.reset ()
# circle, The first parameter is a radius that is positive, the default counterclockwise circle, the radius is negative, the clockwise circle.
# t.circle (-20,90), clockwise, draw an arc radius 20, arc 90
# t.circle (20,90,10), the third argument specifies spent a total of a few unfinished, corresponding to polygon
t. (20 is) Circle
# draw points, t.dot (), a first argument specifies dot radius, the second argument specifies the color
t.dot ()
t.dot (20 is)
t.dot (20 is, 'Blue')

# Revocation action
t.undo ()

# Set turtle moving speed, range 0-10, no parameter returns the current Speed
t.speed (10)

# Return x, y coordinate location
t.xcor ()
t.ycor ()

## turtle position specified distance
t.distance (0,0)

## turtle falling and lifting, moving, do not draw the line when lifted; isdown (): turtle falling returns true, otherwise the turtle be up
t.down ()
t.up ()
t.isdown ()
# Set the size pen returns the current size parameter is empty
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)

## Set the fill color, t.color () display or set pencolor and fillColor
t.fillcolor ()
t.color ( 'Red', 'Blue')

# Fill, fill the display is turned on, begins to fill, end fill
t.filling ()
t.begin_fill ()
t.circle ()
t.end_fill ()

## show, hide turtle, turtle is visible
t.hideturtle ()
t.showturtle ()
t.isvisible ()

# Set the shape turtle, turtle shape when no current display parameters
t.shape ( 'turtle')

##################### event handler
# left mouse button click event, fun for the binding function requires two parameters, click the representative position (x, y ), btn refers to the number of left-click, just click triggered only binding on the turtle. fun = None represents unbound
t.onclick (Fun, BTN =. 1)
t.onrelease ()

################# window control
turtle.bgcolor ()
turtle.bgpic () set or get background image, only supports gif images
turtle.clear ()
turtle.reset ()
Turtle .screensize () window size

Guess you like

Origin www.cnblogs.com/valorchang/p/11283451.html
Recommended