Source code for teek.extras.links

import functools
import webbrowser

_TAG_PREFIX = 'teek-extras-link-'


def _init_links(widget):
    if _TAG_PREFIX + 'common' in (tag.name for tag in widget.get_all_tags()):
        return widget.get_tag(_TAG_PREFIX + 'common')

    old_cursor = widget.config['cursor']

    def enter():
        nonlocal old_cursor
        old_cursor = widget.config['cursor']
        widget.config['cursor'] = 'hand2'

    def leave():
        widget.config['cursor'] = old_cursor

    tag = widget.get_tag(_TAG_PREFIX + 'common')
    tag['foreground'] = 'blue'
    tag['underline'] = True
    tag.bind('<Enter>', enter)
    tag.bind('<Leave>', leave)
    return tag