Python中的 turtle.resizemode()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.resizemode()
此函数用于将 resizemode 设置为以下值之一:“auto”、“user”、“noresize”。如果没有给出参数,则返回当前的 resizemode。 resizemode(“user”) 由带有参数的 shapesize 调用调用。
Syntax : turtle.resizemode(rmode=None)
Parameters:
rmode (optional): one of the strings “auto”, “user”, “noresize”
Different resizemodes have the following effects:
- “auto” adapts the appearance of the turtle corresponding to the value of pensize.
- “user” adapts the appearance of the turtle according to the values of stretchfactor and outlinewidth (outline), which are set by shapesize()
- “noresize” no adaption of the turtle’s appearance takes place.
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# importing package
import turtle
# check default value
print(turtle.resizemode())
Python3
# importing package
import turtle
# print default value
print(turtle.resizemode())
# change mode to auto and check
turtle.resizemode(rmode="auto")
print(turtle.resizemode())
# change mode to user and check
turtle.resizemode(rmode="user")
print(turtle.resizemode())
输出 :
noresize
示例 2:
Python3
# importing package
import turtle
# print default value
print(turtle.resizemode())
# change mode to auto and check
turtle.resizemode(rmode="auto")
print(turtle.resizemode())
# change mode to user and check
turtle.resizemode(rmode="user")
print(turtle.resizemode())
输出 :
noresize
auto
user