Save contents of a Listbox to mysql database

Asked

Viewed 141 times

0

Good morning,

I have a listbox and I’m having a hard time storing the contents of that list in the Mysql database. Someone could help me. I followed code and error below:

    def SaveVariosCodBr(self):
    db=self.conexaoBanco()
    cursor=db.cursor()
    listcod = self.ListCodBrGer.get(ALL)
    sql="insert into "+self.entrPsCodBr.get()+"(codigo,situacao)values('"+listcod+"','ativo')"
    try:
        cursor.execute(sql)
        db.commit()
        print('Dados Gravados')
    except MySQLdb as erro:
        print('Nao conseguiu Gravar')
    db.close()

this is the mistake that:

File "C:\Python27\lib\lib-tk\Tkinter.py", line 2619, in get
return self.tk.call(self._w, 'get', first)
TclError: bad listbox index "all": must be active, anchor, end, @x,y, or a number       

1 answer

0

Diunior, in my opinion the error is occurring here :

listcod = self.ListCodBrGer.get(ALL)

should be like this :

listcod = self.ListCodBr.get(0, END)

as I don’t understand much of mysql I can’t tell you if the time to insert the contents inside the database is correct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.