[Tkinter-discuss] Formatting external data as hyperlinks

Kevin Walzer kw at codebykevin.com
Tue Feb 26 12:31:06 CET 2013


Hi all,

So I have an app that reads data from an external process, and that data 
often has web URL's and e-mail addresses, like so:

----
anacron-2.3-6: Periodic command scheduler
  Anacron executes commands at intervals specified in days
  Unlike cron, it does not assume that the system is running continuously.
  It's ideal for machines such as laptops
  .
  Fink Developer Note:
  If your package requires some sort of recurring activity, you can add a
  script to the <fink prefix>/etc/cron.{daily,weekly,monthly} directory.
  See the run-parts(8) manpage for the structure of these scripts.
  .
  Web site: http://sourceforge.net/projects/anacron
  .
  Maintainer: None <fink-devel at lists.sourceforge.net>
----

I'd like to use effbot's hyperlink class 
(http://effbot.org/zone/tkinter-text-hyperlink.htm) to format the URL's 
and e-mail addresses as hyperlinks with a callback. What I'm not clear 
on is how to do this with a long-running process that loads external 
data. effbot's examples look something like this:

hyperlink = tkHyperlinkManager.HyperlinkManager(text)

def click1():
     print "click 1"

text.insert(INSERT, "this is a ")
text.insert(INSERT, "link", hyperlink.add(click1))
text.insert(INSERT, "\n\n")

It's easy to define a simple text snippet and add a hyperlink tag to it 
as the above example shows, but abstracting this idea to arbitrary text 
is proving difficult for me. Probably some sort of regular expression 
test is called for; can someone suggest how to implement this?

(I've been using a very nice Tk widget, ctext (http://wiki.tcl.tk/4134) 
for this purpose, but while it works great in Tk directly, it seems to 
take a large performance hit when called from Tkinter, which make it 
unsuitable for presenting large amounts of data.)

Any suggestions are appreciated.

--Kevin


-- 
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com


More information about the Tkinter-discuss mailing list