HTML links in a GUI tkinter

Andres Rosado arosado at softhome.net
Tue Jun 4 19:59:57 EDT 2002


At 03:21 PM 6/3/2002 +0000, you wrote:
>Message: 10
>    Date: Mon, 3 Jun 2002 15:23:47 +0000
>    From: Eric Brunel <eric.brunel at pragmadev.com>
>Subject: Re: HTML links in a GUI tkinter
>
>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)
>t.pack()
>
>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, "http://www.python.org", "hlink")
>t.insert(END, "\nAnd text goes on...\n")
>root.mainloop()
>----------------------------------
>
>Control-click on the link and you should see the message "Going to <link
>text>", which may be replaced by a webbrowser.open to actually open the
>URL. To insert a new link, just do:
>t.insert(<pos>, <url>, "hlink")

By far a more simpler solution. Thanks!

>HTH

-----------------------------------
Andres Rosado
Email: andresr at despammed.com
ICQ: 66750646
Homepage: http://andres980.tripod.com/

You should emulate your heros, but don't carry it too far.
Especially if they are dead.






More information about the Python-list mailing list