I have the following problem in this part of my code, I explain: I have a combobox that is filled directly from the database, from there I get the data, then with a button a function is executed to obtain the id of the combobox data and then save the id in the database, the problem is that when doing the sql query to obtain the id it is saved as a list and so it does not work for me I just want the integer to be saved
def guardar():
listaId = []
cursor = conexion.cursor()
Here I made this function to make a query using the data I got from the combobox to get the id of each of the tables, but the ids are saved as lists
for cilindros, empresa, tamano, pico in lista:
cursor.execute("SELECT id FROM empresas WHERE empresa =?", (empresa.get(),))
empresaId = cursor.fetchall()
cursor.execute("SELECT id FROM tamano_precio WHERE tamano =?", (tamano.get(),))
tamanoId = cursor.fetchall()
cursor.execute("SELECT id FROM picos WHERE pico =?", (pico.get(),))
picoId = cursor.fetchall()
listaId.append([empresaId, tamanoId, picoId])
cursor.close()
Here the id is stored in the database
cursor2 = conexion.cursor()
for empresaId, tamanoId, picoId in listaId:
cursor2.execute("INSERT INTO cilindros(empresa_id, pico_id, tamano_id, jefesf_id) VALUES (?, ?, ?, ?)", (str(empresaId), str(picoId), str(tamanoId), str(guardarCedula)))
conexion.commit()
cursor2.close()
Here are the comboboxes, the data you get are the names of the companies, sizes and peaks
ventana5 = Toplevel()
cantidadVacios = cantidadCilindros.get() +1
lista = []
for cilindros in range(1, cantidadVacios):
titulo = tk.LabelFrame(ventana5, text= f"Cilindro {cilindros}")
titulo.pack()
empresa = ttk.Combobox(titulo, width=11)
empresa["values"] = emp()
empresa.current(0)
empresa.pack()
tamano = ttk.Combobox(titulo, width=11)
tamano["values"] = taman()
tamano.current(0)
tamano.pack()
pico = ttk.Combobox(titulo, width=11)
pico["values"] = pic()
pico.current(0)
pico.pack()
lista.append([cilindros, empresa, tamano, pico])
Button(ventana5, text="Guardar", command=guardar).pack()
This is how they are stored: enter image description here
And this is how I want them to be saved: enter image description here