HTML links in a GUI tkinter

Eric Brunel eric.brunel at
Mon Jun 3 11:23:47 EDT 2002

Steve Holden wrote:
> So, all Aurel needs to know now is how to run wxPython widgets inside
> tkinter programs...

Why? Tkinter has everything to do it:

from Tkinter import *

root = Tk()
t = Text(root)

def openHLink(event):
  start, end = t.tag_prevrange("hlink",
                               t.index("@%s,%s" % (event.x, event.y)))
  print "Going to %s..." % t.get(start, end)

t.tag_configure("hlink", foreground='blue', underline=1)
t.tag_bind("hlink", "<Control-Button-1>", openHLink)
t.insert(END, "This is a link\n")
t.insert(END, "", "hlink")
t.insert(END, "\nAnd text goes on...\n")

Control-click on the link and you should see the message "Going to <link 
text>", which may be replaced by a to actually open the 
URL. To insert a new link, just do:
t.insert(<pos>, <url>, "hlink")

- Eric Brunel <eric.brunel at> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list