Re: Programmatic links in a TKinter TextBox



Many thanks Jeff!!!
This is what should be in the TK docs. Your example was very clear.
And now I've learned some new stuff... :)

For my project, I needed to add three pieces of data per link like
this:
text.insert(Tkinter.END, "link", ("a", "href:"+href,"another:This Is
More Data", "last:and one more bit for fun"))

I tweaked the above example here to catch multiple bits by adding a
couple elif statements to the for loop, and removing the break lines.

def click(event):
w = event.widget
x, y = event.x, event.y
tags = w.tag_names("@%d,%d" % (x, y))
for t in tags:
if t.startswith("href:"):
print "clicked href %s" % t[5:]
#commented out the break
elif t.startswith("another:"):
print "clicked href %s" % t[8:]
# commented out the break
elif t.startswith("last:"):
print "clicked href %s" % t[5:]
else:
print "clicked without href"
return "break"

Thanks again, I hope others will find this as useful as I did..

.



Relevant Pages

  • Re: Regexp problem for template language
    ... > second part was only for trying to get all the text in between {% tags ... def test_tokenization_without_curly ... Sean ... Prev by Date: ...
    (comp.lang.ruby)
  • Re: Passing block to Proc#call
    ... tokens with various tags, and I'm matching based on the tags. ... def self.date_scanner *tags, &block ... # this scanner matches, have the tokens processed ...
    (comp.lang.ruby)
  • Re: Ordered Sets
    ... to store the key itself in the Node or the list. ... script that stores only prev and next. ... def discard: ... yield start ...
    (comp.lang.python)
  • Re: Weird things about vertical spacing in HTML
    ... Liam Gibbs wrote: ... been able to correct this problem by removing all EM tags. ... so I can't install other browsers and test the page in them. ...
    (comp.infosystems.www.authoring.html)
  • Re: Can I run an operation on an objects attribute when reading?
    ... When I'm reading the item.tags, I'd like to automagically have the value ... def get_tags: ... Item.tags = tags ... return getattr(self._item, attr) ...
    (comp.lang.python)