I am creating a song notification program in python using Tkinter and bs4. I have extracted songs and their corresponding urls from a site. I have used text widget to store songs and have their urls as key value in a dictionary.
Now I want to add links to the songs name(stored in text widget) so that when I click a particular song, its url is opened in chrome.
Here is the snippet of Code:
from tkinter import *
import webbrowser
from bollywood_top_50 import bollywood_songs_list , bollywood_songs_dict
from international_top_50 import international_songs_list
b_songs_list = bollywood_songs_list()
b_songs_dict = bollywood_songs_dict()
i_songs_list = international_songs_list()
root = Tk()
S = Scrollbar(root)
T = Text(root, height=20, width=30,cursor="hand2")
S.pack(side=RIGHT, fill=Y)
T.pack(side=LEFT, fill=Y)
S.config(command=T.yview)
T.config(yscrollcommand=S.set)
def callback_a():
T.delete(1.0,END)
for songs in b_songs_list:
T.insert(END, songs + '\n')
def callback_b():
T.delete(1.0,END)
for songs in i_songs_list:
T.insert(END, songs + '\n')
bollywood_button = Button(root,text="Bollywood-Top-50", command=callback_a)
bollywood_button.pack()
international_button = Button(root,text="International-Top-50", command=callback_b)
international_button.pack()
Here is the sample output: