Python turtle.Screen().turtles()用法及代码示例 |
您所在的位置:网站首页 › python中turtle是什么意思 › Python turtle.Screen().turtles()用法及代码示例 |
turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。 turtle.Screen().turtles()此函数用于返回屏幕上的海龟列表。这不需要任何论点。 用法: turtle.Screen().turtles()下面是上述方法的实现和一些示例: 范例1: Python3 # import package import turtle # make screen object # and set size sc = turtle.Screen() sc.setup(400,300) # make turlte object t1=turtle.Turtle(shape='square') # do some motion with properties t1.color("red") t1.circle(50) # make another turlte object t2=turtle.Turtle(shape='circle') # do some motion with properties t2.color("green") t2.circle(40) # get all turtle objects on screen print(sc.turtles())输出: [, ] 范例2: Python3 # import package import turtle # make screen object and set size sc = turtle.Screen() sc.setup(400, 300) # make first turtle and do something t1 = turtle.Turtle(shape='square') t1.color("red") t1.circle(50) # make another turtle and do something t2 = turtle.Turtle(shape='circle') t2.color("green") t2.circle(40) # get all turtles object turt = sc.turtles() # use first turtle object turt[0].circle(-40) # use another turtle object turt[1].circle(-50)输出: To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |