The code
def OpenDocument(Doc):
file = "./Account Data/Saved Docs/" + Doc
with open(file, 'r') as f:
content = f.readlines()
print("Document context: " + str(content))
Space()
def BringUpDocs():
global globUser
a = 0
i = 1
e = os.listdir("./Account Data/Saved Docs")
text = "." + globUser
for index in range(len(e)):
if text in e[a]:
if i == 1:
Value = e[a]
SaveData(Value)
else:
Value = e[a]
SaveData(Value)
Button(master, text=e[a],command=lambda *args: OpenDocument(Value)).grid(row=1,column=i)
i = i + 1
a = a + 1`
The problem is that when I run this, all buttons created by this set the variable to the same thing. How would I have them set it to the correct values rather than setting it to the last button created by this function's value? I think that this will help many people who are struggling with this type of question.