As part of my Tkinter application, I am trying to insert links to web pages through a loop. The problem which I am encountering is that, for some reason, the last link is inserted for all elements no matter the amount of links in my list. This is incorrect because I want to have each individual link function if that makes sense. No error messages appear during compile or runtime, the issue is just incorrect behavior. For reference, this is an example version of what I am trying to implement:
import webbrowser
from tkinter import Tk, Label
root = Tk()
links = ["https://itunes.apple.com/us/tv-season/pilot/id271383858?
i=271866344&uo=4&at=1000l3V2",
"https://play.google.com/store/tv/show?amp=&=&cdid=tvseason-
2LA4CTEOrZM&gdid=tvepisode-PNxGMkcus_g&gl=US&hl=en&id=L2wfgMDGiBk",
"https://www.vudu.com/content/movies/details/Breaking-Bad-Pilot/207577",
"https://watch.amazon.com/detail?gti=amzn1.dv.gti.74a9f71f-3d5a-f492-23dc-
3dfbc2404a24",
"https://www.youtube.com/watch?v=PNxGMkcus_g",
"https://www.microsoft.com/en-us/p/season-1/8d6kgwzlcb8z",
"https://www.netflix.com/watch/70196252"]
i = 1
for l in links:
cur_link = Label(root, text="Link #" + str(i), bd=10)
cur_link.pack()
cur_link.bind("<Button-1>", lambda e: webbrowser.open(l))
i += 1
root.mainloop()
The result of running this code is that on click, all 7 (in this case) of the Labels link to Netflix, which is the last link in my links list. I only want Netflix to be connected with Link #7 Label.
I suspect the issue is something to do with handling/storing object references in global variables, but I am not exactly sure how to solve this problem. I have tried to use tkHyperlinkManager, but I run into the same issue as Labels. Any guidance would be appreciated, thank you!