Turtle库学习--TurtleScreen/Screen 方法及对应函数

turtle.bgcolor(*args)

参数
args – 一个颜色字符串或三个取值范围 0…colormode 内的数值或一个取值范围相同的数值3元组

设置或返回 TurtleScreen 的背景颜色

turtle.bgpic(picname=None)

参数
picname – 一个字符串, gif-文件名, “nopic”, 或 None

设置背景图片或返回当前背景图片名称

如果 picname 为一个文件名,则将相应图片设为背景
如果 picname 为 “nopic”,则删除当前背景图片
如果 picname 为 None,则返回当前背景图片文件名

turtle.clear()

turtle.clearscreen()

从中删除所有海龟的全部绘图。将已清空的 TurtleScreen 重置为初始状态: 白色背景,无背景片,无事件绑定并启用追踪。

注意:
此 TurtleScreen 方法作为全局函数时只有一个名字 clearscreen
全局函数 clear 所对应的是 Turtle 方法 clear

turtle.reset()

turtle.resetscreen()

重置屏幕上的所有海龟为其初始状态。

注意:
此 TurtleScreen 方法作为全局函数时只有一个名字 resetscreen
全局函数 reset 所对应的是 Turtle 方法 reset

turtle.screensize(canvwidth=None, canvheight=None, bg=None)

参数
canvwidth – 正整型数,以像素表示画布的新宽度值

canvheight – 正整型数,以像素表示画面的新高度值

bg – 颜色字符串或颜色元组,新的背景颜色

如未指定任何参数,则返回当前的 (canvaswidth, canvasheight)
否则改变作为海龟绘图场所的画布大小

turtle.setworldcoordinates(llx, lly, urx, ury)

参数
llx – 一个数值, 画布左下角的 x-坐标

lly – 一个数值, 画布左下角的 y-坐标

urx – 一个数值, 画面右上角的 x-坐标

ury – 一个数值, 画布右上角的 y-坐标

设置用户自定义坐标系并在必要时切换模式为 “world”。这会执行一次 screen.reset()。
如果 “world” 模式已激活,则所有图形将根据新的坐标系重绘

仔细观察一下程序的运行:

import turtle
from turtle import Turtle

turtle.screensize(canvwidth=2000,canvheight=1500)
turtle.shape("turtle")
turtle.bgcolor("orange")
for i in range(4):
    turtle.forward(100)
    turtle.left(90)

turtle.resetscreen()
turtle.setworldcoordinates(-50, -25, 50, 25)
# turtle.bgpic("0.jpg")
turtle.done()

猜你喜欢

转载自blog.csdn.net/hide_in_darkness/article/details/107633286