There is a task in front of me: selectively delete ttk.Treeview () elements or delete the first one. How do I implement this? Any of these options are suitable.
PS I tried to remove () and delete (), refuses to accept.
There is a task in front of me: selectively delete ttk.Treeview () elements or delete the first one. How do I implement this? Any of these options are suitable.
PS I tried to remove () and delete (), refuses to accept.
Add and update height from previous question .
Get the selected object with .selection() and delete it with .delete(items) .
from tkinter import Tk, ttk class Main(Tk): def __init__(self): super().__init__() self.i = len(c) self.tree = ttk.Treeview(columns=[title], height=self.i, show="headings") self.tree.heading('1', text=title) for i in c: self.tree.insert('', 'end', values=(i,)) self.tree.pack() push = ttk.Button(text='Нажми', command=lambda: self.func(1, 2, 3, 4, 5)).pack() delete_func = ttk.Button(text='Удалить', command=self.del_func).pack() def func(self, *items): for j in items: self.tree.insert('', 'end', values=(j,)) self.tree.config(height=len(self.tree.get_children())) def del_func(self): item = self.tree.selection()[0] self.tree.delete(item) self.tree.config(height=len(self.tree.get_children())) if __name__ == "__main__": c = ['De spasito', 'Spasito', 'Ne Spasito', 'Pasito'] title = '1' root = Main() root.mainloop() Source: https://ru.stackoverflow.com/questions/819409/
All Articles