For
loop parses file and adds info to a dictionary. Then inserts a link into the Text widget that a user can click and it gives them a popup with details from the dictionary. This works fine if only one file is in u but if multiple files are in u
then the tag_bind
uses the last fle in u
for the popfunc function. I understand why it does this but I cant think of a better way go through the loop that avoids this problem. Recommendations?
def popfunc(event, path, dictionary):
win = Toplevel()
txt2 = Text()
txt2.grid()
for key, value in dictionary.items():
if path == key:
txt2.insert('end', value)
txt = Text()
txt.grid()
u = <list of files>
for i in u:
txt.tag_bind('pop', '<Button-1>', lambda event: popfunc(event, i, dictionary))
with open(i, 'r') as f:
h = f.readlines()
for line in h:
<parse file and add info to dictionary>
txt.insert('end', 'User Info: ')
txt.insert('end', 'Click here to see info', 'pop')