Python中的 turtle.screensize()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.screensize()
此方法用于调整海龟正在绘制的画布的大小。如果没有给出参数,则此函数返回当前的 (canvaswidth, canvasheight)。
句法 :
turtle.screensize(canvwidth=None, canvheight=None, bg=None)
参数:Arguments Value Description canvwidth positive integer new width of canvas in pixels canvheight positive integer new height of canvas in pixels bg colorstring or color-tuple new backgroundcolor
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# import package
import turtle
# check the screensize by default
# it varies ide to ide
print(turtle.screensize())
Python3
# import package
import turtle
# set screen
turtle.screensize(canvwidth=400, canvheight=400,
bg="yellow")
Python3
# import package
import turtle
# set turtle
turtle.width(2)
turtle.speed(10)
# loop for pattern
for i in range(10):
turtle.circle(40)
turtle.right(36)
# set screen and drawing remain as it is.
turtle.screensize(canvwidth=400, canvheight=300,
bg="blue")
输出 :
(400, 300)
示例 2:
Python3
# import package
import turtle
# set screen
turtle.screensize(canvwidth=400, canvheight=400,
bg="yellow")
输出 :
示例 3:
Python3
# import package
import turtle
# set turtle
turtle.width(2)
turtle.speed(10)
# loop for pattern
for i in range(10):
turtle.circle(40)
turtle.right(36)
# set screen and drawing remain as it is.
turtle.screensize(canvwidth=400, canvheight=300,
bg="blue")
输出 :