turtle的基本使用

2021-10-10 20:06:08 字數 3955 閱讀 1779

1. 基本操作

1.建立畫布

turtle.setup(寬度,高度)
2.設定筆

# 1)設定筆的顏色

turtle.pencolor(顏色)

# 2)設定線寬

turtle.width(線寬)

# 3)設定速度

turtle.speed(速度值)

- 速度值是1

-10逐漸變大 和 0 對應的速度最快

# 4)設定海龜樣式

turtle.hideturtle(

)/turtle.ht(

)- 隱藏海龜圖示

turtle.showturtle(

)/turtle.st(

)- 顯示龜圖示

turtle.shape(name=

none

)- 設定海龜樣式(「arrow」, 「turtle」, 「circle」, 「square」, 「********」, 「classic」)

3.控制筆移動

# 1)向前走

turtle.forward(距離)

/turtle.fd(距離)

# 2) 向後走

turtle.back(距離)

/turtle.bk(距離)

# 3) 移動到指定位置

tutle.goto(x座標, y座標)

/ turtle.setx(x座標)

/ turtle.sety(y座標)

# 4) 回到開始位置

turtle.home(

)

4.控制筆的方向

# 1)向左轉

turtle.left(角度)

# 2)向右轉

turtle.right(角度)

5.抬起筆和放下筆

# 1)抬起筆

turtle.up()

# 2)放下筆

turtle.down()

6.程式一直執行

turtle.mainloop(

)

#####2. 畫圓

畫圓環

#1) 畫乙個完整的圓

turtle.circle(半徑)

#2) 畫圓環的一部分

turtle.circle(半徑, 角度)

畫實心圓

turtle.dot(直徑)
#####3.填充

# 設定填充顏色

turtle.fillcolor(顏色)

# 開始填充

turtle.begin_fill()

# 結束填充

turtle.end_fill()

4. **不提示解決方案

開啟turtle.py檔案做以下修改:

# 注釋掉

# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +

# _tg_utilities + ['terminator']) # + _math_functions)

# 新新增

__all__ =

['scrolledcanvas'

,'turtlescreen'

,'screen'

,'rawturtle'

,'turtle'

,'rawpen'

,'pen'

,'shape'

,'vec2d'

,'back'

,'backward'

,'begin_fill'

,'begin_poly'

,'bk'

,'addshape'

,'bgcolor'

,'bgpic'

,'bye'

,'clearscreen'

,'colormode'

,'delay'

,'exitonclick'

,'getcanvas'

,'getshapes'

,'listen'

,'mainloop'

,'mode'

,'numinput'

,'onkey'

,'onkeypress'

,'onkeyrelease'

,'onscreenclick'

,'ontimer'

,'register_shape'

,'resetscreen'

,'screensize'

,'setup'

,'terminator'

,'setworldcoordinates'

,'textinput'

,'title'

,'tracer'

,'turtles'

,'update'

,'window_height'

,'window_width'

,'write_docstringdict'

,'done'

,'circle'

,'clear'

,'clearstamp'

,'clearstamps'

,'clone'

,'color'

,'degrees'

,'distance'

,'dot'

,'down'

,'end_fill'

,'end_poly'

,'fd'

,'fillcolor'

,'filling'

,'forward'

,'get_poly'

,'getpen'

,'getscreen'

,'get_shapepoly'

,'getturtle'

,'goto'

,'heading'

,'hideturtle'

,'home'

,'ht'

,'isdown'

,'isvisible'

,'left'

,'lt'

,'onclick'

,'ondrag'

,'onrelease'

,'pd'

,'pen'

,'pencolor'

,'pendown'

,'pensize'

,'penup'

,'pos'

,'position'

,'pu'

,'radians'

,'right'

,'reset'

,'resizemode'

,'rt'

,'seth'

,'setheading'

,'setpos'

,'setposition'

,'settiltangle'

,'setundobuffer'

,'setx'

,'sety'

,'shape'

,'shapesize'

,'shapetransform'

,'shea***ctor'

,'showturtle'

,'speed'

,'st'

,'stamp'

,'tilt'

,'tiltangle'

,'towards'

,'turtlesize'

,'undo'

,'undobufferentries'

,'up'

,'width'

,'write'

,'xcor'

,'ycor'

]

turtle庫的基本運用

示例 pythondraw py import turtle turtle.setup 650,350,200,200 設定窗體的大小和位置 turtle.penup 畫筆起 turtle.fd 250 海龜座標,向後 turtle.pendown 畫筆落 turtle.pensize 25 畫筆寬...

turtle庫的使用

turtle庫是turtle繪圖體系的python實現 1.turtle的繪圖窗體執行 setup設定窗體的大小和位置 turtle.setup width,height,startx,starty startx,starty 為窗體左上角的座標,預設正中心 2.turtle空間座標體系 絕對座標 ...

turtle 函式的使用

turtle 繪製蟒蛇圖形例項 pythondraw.py import turtle turtle.setup 650,350,200,200 turtle.penup turtle.fd 250 turtle.pendown turtle.pensize 25 turtle.pencolor p...