Programmatic links in a TKinter TextBox
Grooooops
JOHNWUN at aol.com
Wed Jun 15 13:28:17 EDT 2005
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..
More information about the Python-list
mailing list