Hello everyone I am currently trying to insert x amount of Listboxes in each Frame of a Notebook, depending on the number of elements in a dictionary and all this from a for loop, now I have created a function for me to print the name of the selected listbox, but the problem is that it only prints the name of the listboxes that have been created in the last Frame, the ones that are created in the first Frame when selecting them, I skipped the error. Excuse me if I explain myself fatally, but I'm very new to Python and really the words are not my thing :). Without further ado I say goodbye thank you very much in advance for the help.
Here's the code I've summarized as much as I could.
from tkinter import *
from tkinter import ttk
root=Tk()
note = ttk.Notebook(root)
def mostrar_nombre(event):
nombrel = str((listbox .get(listbox .curselection())))
print(nombrel)
lista1={"Pestaña1": ["nota1", "nota2"], "Pestaña2": ["block1","block2","block3"]}
tabs = []
for i in (lista1): # Introduce los frames dentro de la lista tabs[] para su futuro uso.
tabs.append(ttk.Frame(note))
contador1=-1
contador2=-1
for i in (lista1):
contador1 += 1
numero= int(contador1)
note.add(tabs[numero], text=i) # Comienza a crear los frames. i=Pestaña1- i=Pestaña2
for e in(lista1[i]):
contador2 += 1
numero = int(contador1)
global listbox
listbox = Listbox(tabs[numero])
listbox.grid(row=0, column=0)
listbox.bind("<<ListboxSelect>>", mostrar_nombre) # Comienza a asignar los listboxs a cada pestaña.
for e in (lista1[i]):
listbox.insert(END, e) # Asigna a cada listbox creado un nombre.
note.pack()
root.mainloop()