I'm using Tkinter to make a music sorting program. I've organized my data into a dictionary, where the keys are the artists and the values are the songs. I've also already been successful at creating a listbox with the artists as the different selections.
The part I can't figure out is how to make the selection from the artist listbox open up a new listbox with all the related songs (the related values from the dictionary). This is what I have so far:
file = open("songs.txt")
music = createdict(file)
keys = sorted(music.keys())
values = music.values()
#Artist Option Listbox with Scrollbar
root = tk.Tk()
root.title("Artist Options")
scrollbar = Scrollbar(root, bg = "grey")
scrollbar.pack(side = RIGHT, fill = Y)
def cureselet(evt):
Lb1.see(ACTIVE)
item = Lb1.get(Lb1.curselection())
return item
Lb1 = Listbox(root, selectmode = SINGLE, font = ('times', 13), width = 50, height = 15, bd = 4, selectbackground = "yellow", bg = "grey")
Lb1.bind(curselet)
c = 0
for i in keys:
Lb1.insert(END,keys[c])
c+=1
Lb1.pack()
Lb1.config(yscrollcommand = scrollbar.set)
scrollbar.config(command = Lb1.yview)
Lb2 = Listbox(Lb1, selectmode = SINGLE, font = ('times', 13), width = 50, height = 15, bd = 4, selectbackground = "yellow", bg = "grey")
Have the user click a button when ready/after something is selected. Use the button callback to execute a function that will do this, with another button to close the 2nd listbox.