It's in tkinter. The last line adds x = len(FRAME_LIST) "Buttons" into the dropdown menu. The problem is they all reference to the same frame (the last in the FRAME_LIST). How to I make it that every Button references a diffrent frame from FRAME_LIST?
for F in FRAME_LIST:
frame = ChallengePage(mainframe,self, F)
self.frames[F] = frame
frame.grid(row = 0, column = 0, sticky = "nsew")
subMenu1.add_command(label = F.id, command = lambda: self.show_frames(F))
EDIT: So to be more precise, when I come across this problem i thought ok, the problem is I need to declare a local variable, so I tried this:
A = F
subMenu1.add_command(label = F.id, command = lambda: self.show_frames(A))
But it didnt work even though the A is declared INSIDE the loop, and redeclared in every loop, it still yields the same result.
I came now across the link: https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
where it shows the solution:
subMenu1.add_command(label = F.id, command = lambda A = F: self.show_frames(A))
Which somehow magically works, but I don't get why it is any diffrent from my local A.