So I did earlier, a few months ago, ask a similar question but I can't seem to apply the same rules/laws as were applied in a previous question of mine. Like my name suggest my understanding of Python is very basic and so I am confused at why his code won't work...
Every time I load a new screen, the old set of boxes should disappear and new only the new ones should be left there. However this is not what happens. Here are pictures to demonstrate:
However I think the problem may lie here in this part of the code:
def deletePanes(self):
print("delete panes")
Panes = []
self.NoOfPanes = 0
I also call Panes = []
in an earlier section of the code which lies in class Application():
. Is the problem possibly that I am calling it twice? What I mean by this is that is it possible that one Panes
list has the old boxes in it and one Panes
has the new set in it and so when it comes to draw on the PyGame screen it draw both old and new boxes? (All of this might make more sense if you have a look at the full code)
Thank you for any help in advance.
When you call
Panes = []
inside a function, it creates a new local variable Panes
and sets it to an empty list.
If it is a global variable, you should call
Panes[:] = []
If it is in the class, you should call
self.Panes = []