📜  Python中的 turtle.mode()函数

📅  最后修改于: 2022-05-13 01:55:28.112000             🧑  作者: Mango

Python中的 turtle.mode()函数

turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。

海龟.mode()

该函数用于设置海龟模式(“标准”、“标志”或“世界”)并执行重置。

以下是上述方法的实现以及一些示例:

示例 1:

Python3
# importing package
import turtle
  
# check by default value
print(turtle.mode())


Python3
# importing package
import turtle
  
# motion with default mode (standard)
# default direction of turtle head 
# is north in standard mode
turtle.forward(180)
  
# set mode to 'logo' mode
turtle.mode(mode='logo')
  
# do some motion
# default direction of turtle head 
# is east in logo mode
turtle.forward(120)
  
# set mode to 'world' mode
turtle.mode(mode='world')
  
# do some motion
turtle.forward(100)
  
# set coordinates of the turtle 
# mode (world) by choice of user
turtle.setworldcoordinates(-500,-500,500,500)


输出 :

standard

示例 2:

Python3

# importing package
import turtle
  
# motion with default mode (standard)
# default direction of turtle head 
# is north in standard mode
turtle.forward(180)
  
# set mode to 'logo' mode
turtle.mode(mode='logo')
  
# do some motion
# default direction of turtle head 
# is east in logo mode
turtle.forward(120)
  
# set mode to 'world' mode
turtle.mode(mode='world')
  
# do some motion
turtle.forward(100)
  
# set coordinates of the turtle 
# mode (world) by choice of user
turtle.setworldcoordinates(-500,-500,500,500)

输出 :