How to create a hyperlink with a Label in Tkinter?

后端 未结 4 1005
逝去的感伤
逝去的感伤 2020-12-01 14:21

How do you create a hyperlink using a Label in Tkinter?

A quick search did not reveal how to do this. Instead there were only solutions

4条回答
  •  情深已故
    2020-12-01 14:49

    Alternatively if you have multiple labels and want the one function for all. That is assuming you have the link as the text

    import tkinter as tk
    import webbrowser
    
    def callback(event):
        webbrowser.open_new(event.widget.cget("text"))
    
    root = tk.Tk()
    lbl = tk.Label(root, text=r"http://www.google.com", fg="blue", cursor="hand2")
    lbl.pack()
    lbl.bind("", callback)
    root.mainloop()
    

提交回复
热议问题