Clickable Tkinter labels

前端 未结 1 1979
深忆病人
深忆病人 2020-12-19 03:26

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

相关标签:
1条回答
  • 2020-12-19 03:28

    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))
    
    0 讨论(0)
提交回复
热议问题