<p>我想定义25个不同的“矩形”,每个矩形有6个不同的属性。我首先创建了一个只有25个不同元素的列表。然后使用不同的循环,我试图将每个矩形的6个属性附加到包含1-25的列表中。这是我得到的错误,我有一种感觉,这是由于我没有分配什么元素“列表”分配新的6个元素。在</p>
<pre><code>Traceback (most recent call last):
File "tryingRectangle.py", line 37, in <module>
rectanglePos.append(x, y, width, height)
TypeError: append() takes exactly one argument (4 given)
# Create the empty array to house the rectangle
rectanglePos = []
rectangleInPos = [rectanglePos]
# Loop 25 times and add rectangle in random x,y position
for i in range(25):
rectanglePos[i] = i
height = random.randint(20,400)
x = i*20
y = 200
width = 15
rectangleInPos.append(rectanglepos[i])
# Ignore me clock = pygame.tme.Clock()
# Loop until user closes
done = False
while done == False:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
# Set the background WHITE
screen.fill(WHITE)
# Process each rectangle
for i in range(len(rectangle)):
# Draw the Rectangle
pygame.draw.rect(SIZE, RED , rectanglePos[i[1]], rectanglePos[i[2]], rectanglePos[i[3]], rectangle[i[4]], 0)
</code></pre>
<p>我知道我可能在这方面做得不对,但我对如何创建列表感到困惑。在</p>