Tkinter: Treeview with repeated values after pressing "query" button

Asked

Viewed 235 times

0

Every time I press the "Query" button treeview updates, but also by adding previous Rows.

    def consultar(): 
    #função que Mostra na treeview todos os produtos cadastrados
                    conn = sqlite3.connect('banco_produtos_cadastrados.db')
                    bd = conn.cursor()
                    bd.execute("SELECT * FROM produtos")
                    rows = bd.fetchall()
                    for row in rows:
                        print(row) # Mostra toda tabela
                        tree.insert("", tk.END, values=row)

tree= ttk.Treeview(janela2, column=( "column1", "column2", "column3", "column4", "column5","column6"), show='headings')
ttk.Style().configure(tree, background = "black", foreground="white", fieldbackground="red")

tree.heading("#1", text="código")
tree.heading("#2", text="Produto")
tree.heading("#3", text="Marca")
tree.heading("#4", text="Fornecedor")
tree.heading("#5", text="Preço")
tree.heading("#6", text="Preço do fornecedor")    
tree.pack()
  • Wouldn’t it be the case to clean the tree before a new query? Or create an algorithm capable of checking the excess items? I didn’t understand your problem.

  • yes, really it would be the case to clean the tree. could help me with that?

  • 1

    That help you?

  • 1

    Problem solved. Mega grateful!

  • Great! Feel free to post the answer or delete the question if you consider that it is too specific to serve other users.

No answers

Browser other questions tagged

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