0

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
3
  • bublist contains the circles. They can be retrieved, used, modified, removed... Commented Oct 25, 2014 at 3:07
  • @wwii Would I be able to run "getX()" and "getY()" for each circle in the list? Commented Oct 25, 2014 at 3:13
  • If Circles have those methods, then yes. Commented Oct 25, 2014 at 11:44

1 Answer 1

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)
answered Oct 25, 2014 at 3:31
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@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)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.