[Tkinter-discuss] putting a series of hyperlinks in a text widget
michael.odonnell at uam.es
Sun Aug 17 06:46:14 CEST 2008
I think you are on to a valid solution: tag each anchor.
I would use 2 tags:
1) A general tag called for example 'link', which you config
a) to present itself as a link (e.g., in blue, underlines)
b) to respond to events, e.g., ButtonRelease
2) a tag for each individual link, which could be an integer
indicating which link it is (e.g., the position of the url in a list
When you insert the text of the anchor in the widget, specify: ('link', str(i))
The action bound to the ButtonRelease event can recover which link was pressed,
and recover the appropriate url to follow.
from Tkinter import *
master = Tk()
txt.insert(END, "Press ")
txt.insert(END, "here ", ('link', str(0)))
txt.insert(END, "for Python. Press ")
txt.insert(END, "here ", ('link', str(1)))
txt.insert(END, "for Heaven.")
txt.tag_bind('link', '<Button-1>', showLink)
On Wed, Aug 13, 2008 at 2:39 AM, Alexnb <alexnbryan at gmail.com> wrote:
> I am having trouble figuring out the best way to do this and would love some
> What I need to do is to create clickable links in a text widget, but there
> will be at max 40. They will all be different. I am wondering what is the
> best way to create a clickable unique url in a text widget. I know that you
> can bind tags, but the problem with that is since each url is unique that
> would mean 40 tags to get what I want... at least, as far as I know, there
> might be a way to do it that I just don't know.
> Sorry if I am being vague, I just don't know what else to say. If you need
> any extra info just reply I would be happy to provide.
> View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p18948087.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
More information about the Tkinter-discuss