I found some similar questions like these: Creating lambda inside a loop
But I couldn't figure out how to implement in my case.
Here is the simplified code:
i=0
for directory in next(os.walk(_src))[1]:
Button[i] = Button(frame, text=directory, command= lambda: GotoDir(_src+directory)
Button[i].grid()
i=i+1
The problem is that I can't fix the variable directory in each button, it all links to the current directory variable value.