turtle
中默认的模式为 standard
,其坐标原点在画布(canvas
)中心,单位为象素(pixel
)。这种从标系也许不是最符合需要求的,因此可以用 setworlcoordinates
自定义坐标系。
setworldcoordinates(llx,lly,urx,ury)
表示屏幕左下角的 (x, y)
和屏幕右上角的 (x, y)
坐标。(文档上说是画布的左下角和右上角坐标,但实测是屏幕的左下角和右上角。)
Set up user-defined coordinate system and switch to mode “world” if necessary. This performs a screen.reset(). If mode “world” is already active, all drawings are redrawn according to the new coordinates.
举例:
# coding=utf-8
from turtle import *
setup(500,500) # 窗口大小 500 x 500 象素
setworldcoordinates(-0.5, 4.5, 4.5, -0.5) # 自定义坐标系统,并切换到 world 模式
goto(0,4)
goto(4,4)
goto(4,0)
goto(0,0)
exitonclick()
屏幕截图如下: