有人可以幫我制作幾個盒子,每個盒子都使用turtle在不同的軸坐標上,
PS試圖在下面的代碼中使用類和物件:
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()
uj5u.com熱心網友回復:
您似乎將隨機的代碼串在一起,希望它能起作用。例如,引數呼叫如下:
..., location=goto(0, 300)
傳遞None給您的初始化程式,因為這就是goto()回傳的內容。并以兩種不同的方式匯入海龜:
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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/443026.html
