justdabbling
justdabbling

Reputation: 11

Python Listboxes

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")

Upvotes: 1

Views: 300

Answers (2)

The-IT
The-IT

Reputation: 728

I agree with user2133443, but I would like to expand on what he said.

You should create a new frame with a scroll bar and a bunch of buttons going down. Each of these buttons act as an 'option' in the option menu. You can allocate a function to each of these buttons that replaces all the labels in another scrolling frame right next it with each of the songs from that artist.

Furthermore, I recommend keeping these new object you're making in a class so it's easy to keep track of them.

If you need any help, just give me a shout.

Upvotes: 0

user2133443
user2133443

Reputation: 171

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.

Upvotes: 1

Related Questions