Can I have 2 listboxes and treat the selections separately?

I have 2 listboxes, why when I select one I lose the selection of the other?
I have a listbox that contains professions and another contains occupations, when I choose some options from one list and go to the other to make selections as well, the selections made in the previous list are lost.

I will leave here my two functions that reorder the options in each list and place first the options to be selected that in the first case come from the database.

def seleccionar_ocupaciones_coincidentes(lista_ocupaciones_coincidentes):
datoso = ocupacion_lisbox.datos
coincidenteso =
restoo =

for ocupacion in datoso:
    if ocupacion["descrip_ocupacion"] in [p["descrip_ocupacion"] for p in lista_ocupaciones_coincidentes]:
        coincidenteso.append(ocupacion)
    else:
        restoo.append(ocupacion)

datos_reorganizadoso = coincidenteso + restoo

ocupacion_lisbox.delete(0, tk.END)
for ocupacion in datos_reorganizadoso:
    ocupacion_lisbox.insert(tk.END, ocupacion["descrip_ocupacion"])

ocupacion_lisbox.datos = datos_reorganizadoso
ocupacion_lisbox.selection_clear(0, tk.END)
for i, ocupacion in enumerate(coincidenteso):
    for j, dato in enumerate(datos_reorganizadoso):
        if ocupacion["descrip_ocupacion"] == dato["descrip_ocupacion"]:
            ocupacion_lisbox.selection_set(j)
            ocupacion_lisbox.activate(j)
            break

#************************************************************************************************
def seleccionar_profesiones_coincidentes(lista_profesiones_coincidentes):
datos = profesion_lisbox.datos
coincidentes =
resto =

for profesion in datos:
    if profesion["descrip_prof"] in [p["descrip_prof"] for p in lista_profesiones_coincidentes]:
        coincidentes.append(profesion)
    else:
        resto.append(profesion)

datos_reorganizados = coincidentes + resto

profesion_lisbox.delete(0, tk.END)
for profesion in datos_reorganizados:
    profesion_lisbox.insert(tk.END, profesion["descrip_prof"])

profesion_lisbox.datos = datos_reorganizados
profesion_lisbox.selection_clear(0, tk.END)
for i, profesion in enumerate(coincidentes):
    for j, dato in enumerate(datos_reorganizados):
        if profesion["descrip_prof"] == dato["descrip_prof"]:
            profesion_lisbox.selection_set(j)
            profesion_lisbox.activate(j)
            break

Hello,

just an fyi, to properly format your script so that it appears as it would on your editor, follow these instructions (it will help to review your script):

For example, to appear like this:

def calc_square(x, y):
    return x * y

I reviewed your script. Additional information is required including the tkinter set up.

Here is a sample screenshot of a potential solution (you can select the professions and occupations and move them between listboxes with ease - if in an actual program, you can add additional code to act upon the changes):

Thanks for your reply. These are two different lists. What’s in one list is selected in that same list, meaning it’s not passed to a secondary list. I have one list where I store professions and another where I manage possible occupations. Now, I’ve been doing some reading and discovered that the Tkinter libraries, at a visual level, don’t handle this component (listbox) showing selections made in more than one list, even though said selection is present internally.

For example, what I am looking for is that, for example: when selecting the profession list and then going to select occupations, the selection of both lists is visually maintained.

For this, per the following thread, apparently you need to configure the exportselection attribute to zero when creating your listboxes to have this desiredd functionality.

Here is selecting two listboxes at the same time:

Hope this helps.