Skip to content
Permalink
82e58ae2df
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
43 lines (31 sloc) 1.37 KB
#########################################################################
# External code to allow insertion of hyperlinks in tkinter text widget #
# Creator: Fredik Lundh #
# Source: http://effbot.org/zone/tkinter-text-hyperlink.htm #
#########################################################################
from tkinter import *
class HyperlinkManager:
def __init__(self, text):
self.text = text
self.text.tag_config("hyper", foreground="blue", underline=1)
#self.text.tag_bind("hyper", "<Enter>", self._enter) #Removed to prevent conflict with pressing Enter to send a message
self.text.tag_bind("hyper", "<Leave>", self._leave)
self.text.tag_bind("hyper", "<Button-1>", self._click)
self.reset()
def reset(self):
self.links = {}
def add(self, action):
# add an action to the manager. returns tags to use in
# associated text widget
tag = "hyper-%d" % len(self.links)
self.links[tag] = action
return "hyper", tag
def _enter(self, event):
self.text.config(cursor="hand2")
def _leave(self, event):
self.text.config(cursor="")
def _click(self, event):
for tag in self.text.tag_names(CURRENT):
if tag[:6] == "hyper-":
self.links[tag]()
return