Basically, I am trying to parse the information from a list into lines in a text widget where each line has a hyperlink related to a field from the list. I am using effbot's HyperlinkManager to attempt to accomplish this. What I currently have is this:
link = hyperlink.link(panel)
if table == '1':
panel.insert(END,' [Part Number] [Part Name]\n')
for row in (queries.partQuery(table,partResult.get())):
number = row[1]
name = row[2]
panel.insert(END,'*[')
panel.insert(END,number, link.add(lambda: test(number)))
panel.insert(END,']')
panel.insert(END,' ' * (25-len(number)))
panel.insert(END,name)
panel.insert(END,'\n')
panel.config(state='disabled')
def test(x):
print (x)
partQuery returns rows from a MySQL db which match certain search criteria, and then I am attempting to insert each result as a line in the text widget 'panel', however, I want the first field in the line (number) to be a hyperlink which I can then click to call a function (test, in this example), and perform an action using 'number' as a variable.
What is occurring however, is that the last result returned is being save as 'number', so whenever I click on one of the links generated in a search, regardless of the line, the last result is printed.
Thanks in advance to anyone who takes time to help me with this conundrum.
EDIT: After following the link in Abarnert's comment, I was able to resolve this issue simply by changing lambda: test(number)
to lambda number=number: test(number)
.