tkinter : how do I remove all the entries from the treeview and also clear the column names

user13412850

I am able to delete all the content of the tree view using the code

tree.delete(*tree.get_children())

However the column names remain, and my treeview is pulling different tables so I ideally dont want any column names when rest of the data is deleted. How can I do that?

enter image description here

root = Tk()
root.minsize(width=600, height=700)
#root.resizable(width=0, height=0)

tree = ttk.Treeview(root, selectmode='browse',height='10')
tree.place(x=330, y=45)

vsb = ttk.Scrollbar(root, orient="vertical", command=tree.yview)
vsb.place(x=320, y=45, height=200 + 180)

tree.configure(yscrollcommand=vsb.set)

#frm = Frame(root)
#frm.pack(padx=0, pady=10, anchor='nw')
#frm.pack(side=tk.LEFT,padx=0,pady=10)
#frm.pack(padx=0,pady=10)

tree["columns"] = (1,2)
tree['show'] = 'headings'
tree['height'] = '20'

tree.column(1, width=150, anchor='c')
tree.heading(1, text="Date")
tree.column(2, width=150, anchor='c')
tree.heading(2, text="GT")


def delete_command():
    tree.delete(*tree.get_children())


b2 = Button(root, text="delete all", width=12, command=delete_command)
b2.place(x=130, y=45)

root.title('New Data')
root.geometry('650x500')
#root.resizable(False,False)
root.mainloop()

Saad

You can change your heading's text = "" by getting all the columns from tree['columns'] and resetting them like so.

def delete_command():
    for col in tree['columns']:
        tree.heading(col, text='')
    tree.delete(*tree.get_children())

But in case you also mean to delete all columns then put tree["columns"] = () line in your delete_command function to clear all the columns.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I correctly remove all text from column in Pandas?

How do I remove all commas from a text column in PostgreSQL

How do I remove text from strings in all the rows in a column?

Can I remove whitespace from all column names with dplyr?

How to clear an entire Treeview with Tkinter

How to remove numbers from all column names / headers in a dataframe

Python Tkinter Treeview search all entries

How do I remove 'Places' entries from the Nautilus sidebar?

How do I remove duplicate entries from Dash on 18.04?

How do I remove special characters found on column names in R

How do I get all distinct property names from a JSON column?

How do i change all the column names in a dataframe, from a long string?

How do I stop FullRowSelect from also selecting a column header

How do I remove all elements in a tkinter GUI?

How do I put all column names in a php array?

Python Tkinter, How do I get the subitems of an Item in Tkinter TreeView?

How do I clear all styles from a child element?

How do I clear the text in a Label with tkinter?

How do I remove duplicate datetime and also convert one column value into new column name?

How do I remove deleted branch names from autocomplete?

How do I remove Blank Space from File Names

How can I remove all entries of a factor when the number of entires without values in a column is below a threshold?

How do I get data from a table of entries I've generated in Python Tkinter?

How do I get schema / column names from parquet file?

How do I pivot values from rows into column names in Postgres?

How do I convert only the column names from vertical to horizontal

How do I remove all the duplicates in each column respectively?

How Do I Remove nchar less then 10 in all column

How do I view all of the entries in man?