Save contents of a Listbox in the mysql database

1

Good morning,

I have a listbox and am having trouble storing the contents of this list in the Mysql database. Can anybody help me. I followed the 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 error that gives:

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       
    
asked by anonymous 13.11.2016 / 15:44

1 answer

0

Diunior, in my opinion the error is occurring here:

listcod = self.ListCodBrGer.get(ALL)

should look like this:

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

As I do not understand much of mysql I can not tell you if the time to insert the contents inside the database is correct.

    
04.12.2018 / 15:17