Hyperlink in Tkinter Text widget? Hyperlink in Tkinter Text widget? tkinter tkinter

Hyperlink in Tkinter Text widget?


If you don't want to use a text widget, you don't need to. An alternative is to use a label and bind mouse clicks to it. Even though it's a label it still responds to events.

For example:

import tkinter as tkclass App:    def __init__(self, root):        self.root = root        for text in ("link1", "link2", "link3"):            link = tk.Label(text=text, foreground="#0000ff")            link.bind("<1>", lambda event, text=text: self.click_link(event, text))            link.pack()    def click_link(self, event, text):        print("You clicked '%s'" % text)root = tk.Tk()app = App(root)root.mainloop()

If you want, you can get fancy and add additional bindings for <Enter> and <Leave> events so you can alter the look when the user hovers. And, of course, you can change the font so that the text is underlined if you so choose.

Tk is a wonderful toolkit that gives you the building blocks to do just about whatever you want. You just need to look at the widgets not as a set of pre-made walls and doors but more like a pile of lumbar, bricks and mortar.


"blue" should indeed be acceptable (since you're on Windows, Tkinter should use its built-in color names table -- it might be a system misconfiguration on X11, but not on Windows); therefore, this is a puzzling problem (maybe a Tkinter misconfig...?). What happen if you use foreground="#00F" instead, for example? This doesn't explain the problem but might let you work around it, at least...