Skip to Content
Menu
This question has been flagged
2 Replies
1519 Views

Hello
In the tree view, I need to make the rows that have already been checked and printed uncheckable.


My goal is to make the already printed rows unprintable, and change their background color.


I know how to add a button with javascript but, I don't know how to select the rows. please can someone help me, I really need.

Avatar
Discard
Best Answer

Try below:

import tkinter as tkimport tkinter.ttkdef select(): curItems = tree.selection() tk.Label(root, text="\n".join([str(tree.item(i)['values']) for i in curItems])).pack()root = tk.Tk()tree = tkinter.ttk.Treeview(root, height=4)tree['show'] = 'headings'tree['columns'] = ('Badge Name', 'Requirement', 'Cost', 'Difficulty')tree.heading("#1", text='Badge Name', anchor='w')tree.column("#1", stretch="no")tree.heading("#2", text='Requirement', anchor='w')tree.column("#2", stretch="no")tree.heading("#3", text='Cost', anchor='w')tree.column("#3", stretch="no")tree.heading("#4", text='Difficulty', anchor='w')tree.column("#4", stretch="no")tree.pack()tree.insert("", "end", values=["IT Badge", "Track Computer", "$1.50", "2"])tree.insert("", "end", values=["Selfless Badge", "Track Yourself", "$100.50", "10"])tree.insert("", "end", values=["Tracking Badge", "Track Animal", "$4.50", "7"])tree.bind("", lambda e: select())root.mainloop()

In the code, select multiple items by pressing Ctrl and clicking on rows and then hit Enter
Avatar
Discard
Author Best Answer

Thank you for your proposal Bassam Saleh,


Please, how to use this solution?

Avatar
Discard