I receive an error updating the TreeView, after clicking on the button to filter the data of a database through two comboboxes. The filtering appears to be successful, but only the staff ID is displayed in the tree view and not all related data. Without using the filter button, everything is fine.
This is the function of the button that allows filtering and re-display after filtering. The problem is the refresh here:
def filtracampionati(): tv.delete(*tv.get_children()) campionati = combo_Campionato.get() giornate = combo_Giornate.get() cursor.execute('SELECT * FROM ARCHIVIO_Risultati WHERE campionato=? AND giornata=?',(campionati, giornate,)) result=[row[0] for row in cursor] for row in result: tv.insert("", END, values=row)
I get an error in the function def getData (event). I get the error: IndexError: list index out of range. The problem is the function I created for the button, because the problem occurs at the time of filtering and re-viewing. Without filtering everything is ok. How can I fix the feature? Thanks
def getData(event): selected_row = tv.focus() data = tv.item(selected_row) global row row = data["values"] #print(row) campionato.set(row[1]) giornata.set(row[2]) calendario.set(row[3]) ore.set(row[4]) minuti.set(row[5]) squadra_casa.set(row[6]) squadra_fuori.set(row[7]) ris_sq_casa.set(row[8]) ris_sq_fuori.set(row[9]) def dispalyAll(): tv.delete(*tv.get_children()) for row in db.fetch(): tv.insert("", END, values=row)
Advertisement
Answer
It is because result=[row[0] for row in cursor]
will only get the first field from each row.
To get all the fields from each row, simply
- remove
result=[row[0] for row in cursor]
- change
for row in result:
tofor row in cursor:
def filtracampionati(): tv.delete(*tv.get_children()) campionati = combo_Campionato.get() giornate = combo_Giornate.get() cursor.execute('SELECT * FROM ARCHIVIO_Risultati WHERE campionato=? AND giornata=?',(campionati, giornate,)) for row in cursor: tv.insert("", END, values=row)