Clickable hyperlinks
Terry Reedy
tjreedy at udel.edu
Thu Jan 5 01:17:37 EST 2017
On 1/5/2017 12:11 AM, Deborah Swanson wrote:
> Terry Reedy wrote, on January 04, 2017 3:58 PM
>> To have a string interpreted as a clickable link, you send the string
> to
>> software capable of creating a clickable link, plus the information
>> 'this is a clickable link'*. There are two ways to tag a string as a
>> link. One is to use markup around the url in the string itself.
>> '<url>' and html are example. Python provides multiple to make this
>> easy. The other is to tag the string with a separate argument. Python
>
>> provides tkinter, which wraps tk Text widgets, which have a powerful
> tag
>> system. One can define a Link tag that will a) cause text to be
>> displayed, for instance, blue and underlined and b) cause clicks on
> the
>> text to generate a web request. One could then use
>> mytext.insert('insert', 'http://www.example.com', Link)
>> Browser must do something similar when they encounter when they
>> encounter html link tags.
>
> I've actually moved on from my original question to one of opening a url
> in a browser with python, which seems to be a much more easily achieved
> goal.
> But someone else mentioned tkinter, and I looked at it while ago but
> haven't used it for anything. That really could be the way to go if you
> want to make clickable links, although you still need some kind of
> internet engine to open the url in a browser.
IDLE allows a user to add help menu entries that, when clicked on, open
either a local file or an internet url. For instance, adding the pair
'Pillow' and "https://pillow.readthedocs.io/en/latest/" in the Settings
dialog adda "Pillow" to the help menu (after the standard stuff).
Clicking on Help => Pillow opens
"https://pillow.readthedocs.io/en/latest/" in the default browswer.
IDLE just used the webbrowser module to do this. No use re-inventing
the wheel. If instead "Pillow" were a link in text, the click handler
should do something similar.
> You say, "There are two ways to tag a string as a link. One is to use
> markup around the url in the string itself. '<url>' and html are
> examples. Python provides multiple ways to make this easy."
>
> Can you tell me where I'd begin to look for these? Are they in the core
> language, or in packages?
I was referring to using either % or .format string formatting. Both
are in the core and described somewhere in the Library manual. '%'
should be in the Symbols page of the Index and 'format' on the 'F' page.
--
Terry Jan Reedy
More information about the Python-list
mailing list