使用乌龟创建盒子
creating boxes using turtle
谁能帮我制作几个盒子,每个盒子都在不同的坐标轴上使用 turtle,
P.S。尝试在以下代码中使用 class 和对象:
import turtle
from turtle import *
# window:
window = turtle.Screen()
window.bgcolor("white")
window.title("Process flow")
class a:
penup()
shape("square")
speed(0)
def __init__(self, reshape, color, location):
self.reshape = reshape
self.color = color
self.location = location
start_node1 = a(reshape=shapesize(stretch_wid=1, stretch_len=3), color=color("light blue"), location=goto(0, 300))
start_node2 = a(reshape=shapesize(stretch_wid=1, stretch_len=3), color=color("yellow"), location=goto(0, 270))
print(start_node1)
print(start_node2)
done()
您似乎将随机的代码串在一起,希望它能起作用。例如。参数调用如:
..., location=goto(0, 300)
将 None
传递给您的初始化程序,因为这就是 goto()
returns。并以两种不同的方式导入海龟:
import turtle
from turtle import *
表明您在概念上遇到了麻烦。以下是我对您的代码进行的修改,以在不同位置显示不同颜色和大小的框,以尽可能多地保留原始代码的“风味”:
from turtle import Screen, Turtle
class Box(Turtle):
def __init__(self, reshape, color, location):
super().__init__(shape='square', visible=False)
self.shapesize(**reshape)
self.color(color)
self.speed('fastest')
self.penup()
self.goto(location)
self.showturtle()
screen = Screen()
screen.title("Process flow")
start_node1 = Box(reshape={'stretch_wid':1, 'stretch_len':3}, color='light blue', location=(100, 300))
start_node2 = Box(reshape={'stretch_wid':2, 'stretch_len':4}, color='yellow', location=(-100, 270))
screen.exitonclick()
谁能帮我制作几个盒子,每个盒子都在不同的坐标轴上使用 turtle,
P.S。尝试在以下代码中使用 class 和对象:
import turtle
from turtle import *
# window:
window = turtle.Screen()
window.bgcolor("white")
window.title("Process flow")
class a:
penup()
shape("square")
speed(0)
def __init__(self, reshape, color, location):
self.reshape = reshape
self.color = color
self.location = location
start_node1 = a(reshape=shapesize(stretch_wid=1, stretch_len=3), color=color("light blue"), location=goto(0, 300))
start_node2 = a(reshape=shapesize(stretch_wid=1, stretch_len=3), color=color("yellow"), location=goto(0, 270))
print(start_node1)
print(start_node2)
done()
您似乎将随机的代码串在一起,希望它能起作用。例如。参数调用如:
..., location=goto(0, 300)
将 None
传递给您的初始化程序,因为这就是 goto()
returns。并以两种不同的方式导入海龟:
import turtle
from turtle import *
表明您在概念上遇到了麻烦。以下是我对您的代码进行的修改,以在不同位置显示不同颜色和大小的框,以尽可能多地保留原始代码的“风味”:
from turtle import Screen, Turtle
class Box(Turtle):
def __init__(self, reshape, color, location):
super().__init__(shape='square', visible=False)
self.shapesize(**reshape)
self.color(color)
self.speed('fastest')
self.penup()
self.goto(location)
self.showturtle()
screen = Screen()
screen.title("Process flow")
start_node1 = Box(reshape={'stretch_wid':1, 'stretch_len':3}, color='light blue', location=(100, 300))
start_node2 = Box(reshape={'stretch_wid':2, 'stretch_len':4}, color='yellow', location=(-100, 270))
screen.exitonclick()