In this GUI there are some Entries that what they do is allow to enter information to be stored in a MySQL database. The Listbox basically displays one of the fields in the database (the name), which in fact is one of the Entry.
In addition, when double clicking on one of the elements of the Listbox all the Entry are loaded with the corresponding information of the database. But, what I'm trying to do is show the name next to the last name, and when double-clicking on one of them, do the same action: load the information according to each Entry field.
This is the code that loads the names in the Listbox. Reviewed is the option to display the names and surnames:
def cargar_lista():
try:
connect.commit()
display = "SELECT p_nombres, p_apellidos FROM propietarios order by p_nombres"
cursor.execute(display)
registros = cursor.fetchall()
lb.delete(0, END)
for item in registros:
nombres = item[0]
apellidos = item[1]
#lb.insert(END, nombres)
lb.insert(END, nombres + ' ' + apellidos)
except:
showerror ("Mensaje", "Error al cargar los propietarios.")
And this is part of the code that loads the information in the Entries:
def llenar_campos():
i = lb.curselection()[0]
valor = lb.get(i)
edit = """SELECT * FROM propietarios WHERE p_nombres=("%s");""" % (valor)
cursor.execute(edit)
result = cursor.fetchall()
connect.commit()
for item in result:
d1 = item[1] #CC/nit
d2 = item[2] #título
d3 = item[3] #Fingreso
d4 = item[4] #razón social
d5 = item[5] #Ciudad
d6 = item[6] #Nombres
d7 = item[7] #Apellidos
d8 = item[8] #Dir casa
d9 = item[9] #Teléfono
d10 = item[10] #Dir oficina
d11 = item[11] #Tel oficina
d12 = item[12] #Fax
d13 = item[13] #Email
cedula.set(d1)
titulo.set(d2)
ingreso.set(d3)
rsocial.set(d4)
residencia.set(d5)
nombres.set(d6)
apellidos.set(d7)
direccion.set(d8)
telefono.set(d9)
oficina.set(d10)
tel.set(d11)
telfax.set(d12)
correo.set(d13)
bloquear() #Bloquea los Entries