13

I will be populating a frame with a list of labels representing URLs. The url's will be fed in from a list and can be between 3 and 5 in number, decided by user. What is the easiest way to make these url's clickable, so the user can get to the website displayed? Is there a better way to do this than use labels?

Thanks

SquidsEnMasse
  • 716
  • 2
  • 7
  • 17

1 Answers1

26

Labels are fine I think. You just need to bind a callback to a mouse click.

def open_url(url):
    pass #Open the url in a browser

for i,url in enumerate(url_list):
    label=tk.Label(frame,text=url)
    label.grid(row=i)
    label.bind("<Button-1>",lambda e,url=url:open_url(url))
mgilson
  • 300,191
  • 65
  • 633
  • 696