[Tkinter-discuss] putting a series of hyperlinks in a text widget
alexnbryan at gmail.com
Sun Aug 17 07:11:34 CEST 2008
You know, I think this is exactly what I was looking for.
Thanks for your help!
Mick O'Donnell wrote:
> Dear Alex,
> 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
> of urls).
> When you insert the text of the anchor in the widget, specify: ('link',
> The action bound to the ButtonRelease event can recover which link was
> and recover the appropriate url to follow.
> from Tkinter import *
> master = Tk()
> LINKS=("http://www.python.org", "http://www.heaven.com")
> def showLink(event):
> idx= int(event.widget.tag_names(CURRENT))
> print LINKS[idx]
> txt.pack(expand=True, fill="both")
> 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_config('link', foreground="blue")
> 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
>> What I need to do is to create clickable links in a text widget, but
>> 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
>> 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,
>> 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
>> any extra info just reply I would be happy to provide.
>> View this message in context:
>> Sent from the Python - tkinter-discuss mailing list archive at
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p19017586.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
More information about the Tkinter-discuss