How do I make it so that the circles in this list can be modified or removed later on? Isn't the list different from the actual objects?
def drawAllBubbles(window,numOfBubbles):
bublist=list()
for x in range(numOfBubbles):
p1= random.randrange(1000)
p2= random.randrange(1000)
center= graphics.Point(p1,p2)
bubx = center.getX()
buby = center.getY()
r = random.randint(1, 255)#randomize rgb values
g = random.randint(1, 255)
b = random.randint(1, 255)
circle = graphics.Circle(center, 5)
circle.setFill(color_rgb(r, g, b))
circle.setOutline("black")
circle.draw(window)
bublist.append(circle)
return bublist
window.getMouse()
This part of the script essentially draws
enter image description here
And then returns a list of circles.
asked Oct 25, 2014 at 3:04
aero26
1551 gold badge3 silver badges11 bronze badges
1 Answer 1
The objects are contained in bublist
If you iterate over the list, you can change, remove, or redraw the circles. For example:
for bubble in bublist:
bubble.setOutline("green")
bubble.draw(window)
Sign up to request clarification or add additional context in comments.
2 Comments
aero26
for bubble in bublist: a= bubble.getCenter() ` b = a.getX()` c = a.getY() print(a) For some reason, I can't get this to print.Tom Grant
@aero26 That line of code will try to print
a, which refers to the Point object returned by bubble.getCenter(). I assume you're trying to print the coordinates, in which case you should try print((b, c)). In Python 2.x: print (b, c)lang-py
bublistcontains the circles. They can be retrieved, used, modified, removed...Circles have those methods, then yes.