[Python] Python, Tkinter, show list as an Excel sheet in a window just one time?

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list with Customer data (Name, Address, ID) in Python and a button in Tkinter window. When I click on "Show List_1" button then I see the list as a table use treeview so it works. When I click again, then I see two times the table, when click again then tree times. How does it work show the list just one time and just "refresh" the window, when I click on the button to show it?

    I tried to use treeview.delete and destroy() function, but then when I click on the button, I see nothing, nothing happens.

    def Vevok_Listazasa():

    Lista = [Vevok("ID_1","Ceg_1","Cim_1"),
    Vevok("ID_2","Ceg_2","Cim_2"),
    Vevok("ID_3","Ceg_3","Cim_3")]

    tree = ttk.Treeview(window, column=("c1","c2","c3"), show='headings')
    tree.column("#1", anchor=CENTER)
    tree.heading("#1", text="ID")
    tree.column("#2", anchor=CENTER)
    tree.heading("#2", text="Vevo_Nev")
    tree.column("#3", anchor=CENTER)
    tree.heading("#3", text="Ceg_cim")

    index = iid = 0

    for item in Lista:
    tree.insert("", index, iid, values=item)
    index = iid = index+1

    tree.pack()
    tree.destroy()

    Continue reading...

Compartilhe esta Página