AttributeError: 'StringVar' object has no attribute 'curselection'

0

Good morning. I have an error when selecting my Listbox. I do not know what I'm doing wrong if everything is identical to another code where it works for me. What I'm trying to do is show a table in my BD in a Listbox and that when selecting an item the Entry is filled with the available information to modify, once the data is modified, the update is saved by recording the data in the table again . I already managed to do it with other windows but in this I failed and I do not understand why. The error says that the StringVar object does not have the Curselection attribute. Any solution?

'
    #DEFINICION DEL LISTBOX

    self.obtenCarrera = StringVar()
    self.carrera = Listbox(self.frameCarrera, listvariable=self.obtenCarrera, width=40, height=20,
        font=("arial", 12),
        selectbackground="medium turquoise",
        exportselection=0,
        highlightcolor="steel blue",
        selectmode=BROWSE,
        yscrollcommand=self.scroll.set)
    self.carrera.pack(side=LEFT, fill=BOTH)
    self.carrera.insert(0, '                           CAERRERAS')
    self.carrera.insert(1, " ")

#SELECCION PARA MOSTRAR EN EL LISTBOX
    cursor.execute("SELECT c.id_carrera, '_______________', c.nombre FROM carreras as c ;")
    inforCarreras = cursor.fetchall()

    for carrera in inforCarreras:
        self.carrera.insert(2, carrera)

    def obtener():
        self.posicion = self.carrera.curselection()  # la variable hola obtiene el ídice (posición) en número de la seleccion. guarda la seleccion del cursor
        self.infor = self.carrera.get(self.posicion)  # La variable h obtiene los datos del índice (posición) seleccionados.

    # OBIENE ID USUARIO Y LA MUESTRA EN EL ENTRY
        cursor.execute("SELECT id_carrera FROM carreras WHERE id_carrera = " + str(self.infor[0]) + ";")
        self.idcarrera = cursor.fetchone()
        self.idcarrera.set(self.idcarrera[0])

    # OBIENE NOMBRE Y LA MUESTRA EN EL ENTRY
        cursor.execute("SELECT nombre FROM carreras WHERE nombre = '" + self.infor[2] + "';")
        self.nomb = cursor.fetchone()
        self.carrera.set(self.nomb[0])

# ELIMINAR#

    def eliminar():
        self.posicion = self.carrera.curselection()  # la variable posicion obtiene el ídice (posición) en número de la seleccion.
        self.infor = self.carrera.get(self.posicion)  # La variable h obtiene los datos del índice (posición) seleccionados.
        cursor.execute("DELETE FROM carreras WHERE id_carrera = " + str(self.infor[0]) + ";")
        self.carrera.delete(self.posicion)
        conexion.commit()
#MÉTODO PARA MODIFICAR
    def modificar():

        self.idus = self.idcarrera.get()
        self.n = self.carrera.get()

        cursor.execute("SELECT id_carrera FROM carreras WHERE id_carrera = '" + str(self.infor[0]) + "';")
        consul = cursor.fetchone()
        self.modif = consul[0]

        sql = "UPDATE carreras as c SET c.id_carrera = %d, c.nombre = '%s' WHERE u.id_carrera= %d" % (self.idus, self.n, self.modif)
        cursor.execute(sql)
        conexion.commit()
        messagebox.showinfo("ACTUALIZACIÓN EXITOSA!!", "        Datos actualizados correctamente. \n\n")

#LIMPIO LOS ENTRY
        self.idcarrera.set("")
        self.carrera.set("")

    self.modif = IntVar()  # variable para obtener la posición
    self.idus = IntVar()
    self.n = StringVar()'
    
asked by pythonista7 12.05.2018 в 15:42
source

0 answers