How To Add A Link To Text In Tkinter Text Widget With Feedparser?
I would like to build a simple rss reader. I use the following code: import tkinter as tk import feedparser import sqlite3 import webbrowser NewsFeed = feedparser.parse('https://ww
Solution 1:
You need to use tag_bind()
instead of bind()
because bind()
is widget-wise:
def output():
for i in range(40):
entry = NewsFeed.entries[i]
textInput.tag_config("a", foreground="black")
# str(i) is used in tag_bind() and "a" can be used for showing the link in underline
textInput.insert(tk.END, entry.title + "\n\n", ("a", str(i)))
textInput.insert(tk.END, entry.summary + "\n\n", "b")
textInput.tag_bind(str(i), "<1>", lambda e, url=entry.link: callback(url))
...
textInput.tag_configure("a", underline=True) # show link with underline
Post a Comment for "How To Add A Link To Text In Tkinter Text Widget With Feedparser?"