

Stack.extend(check_list.Summary: in this tutorial, you’ll learn about the Tkinter Treeview widget and how to use it to display both tabular and hierarchical data. Set_status = check_list.uncheck if check_list.checked(iid) else check_list.check If the status of an item is toggled, the status of all its descendants You can use the clicked parameter to define a new behavior when an item isĬlicked. em(iid, text=text + self._unchecked)Ĭheck_list = TtkCheckList(root, height=len(items)) Status = self._unchecked if checked else self._checked

Text=text+" "+self._unchecked, open=True) Self.insert(parent_iid, index='end', iid=item, Parent_iid, text = item.rsplit(self._separator, maxsplit=1) The item is the list of nodes separatedīy dots: ``. lumn('#0', width=width, stretch=tk.YES)Īdd an item to the checklist. Self._clicked = self.toggle if clicked is None else clicked Ttk.Treeview._init_(self, master, **kwargs) Other parameters are passed to the `TreeView`. :param unchecked: the character for a checked box (default is "\u2612") :param unchecked: the character for an unchecked box (default is

:param separator: the item separator (default is `'.'`) :param clicked: the optional function if a checkbox is clicked. :param width: the width of the check list Unchecked=BALLOT_BOX, checked=BALLOT_BOX_WITH_X, **kwargs): import tkinter as tkĭef _init_(self, master=None, width=200, clicked=None, separator='.', The class TtkCheckList inherits ttk.Treeview, hence the usual parameters/methods of Treeview can be used.
Treeview tkinter update#
We can update the item name when the text is clicked. Those character are located after the item name and are used to check the current state: em(iid, "text") is either ☐ or ☒. Rather than using an image to represent the checkbox, we can use two characters provided by Unicode: If you are stuck with Ttk (as I am), here is an solution based on idea. If ("unchecked" in tags) or ("tristate" in tags):Īn improved version of CheckboxTreeview is available in the ttkwidgets module. X, y, widget = event.x, event.y, event.widget """ check or uncheck box when clicked """ # at least one box is checked and item's box is unchecked """ uncheck the box of item and change the state of the boxes of item's """ uncheck the boxes of item's descendant """ """ put the box of item in tristate and change the state of the boxes of # at least one box is not checked and item's box is checked """ check the box of item and change the state of the boxes of item'sī = """ check the boxes of item's descendants """ """ same method as for standard treeview but add the tag 'unchecked'Īutomatically if no tag among ('checked', 'unchecked', 'tristate')Įlif not ("unchecked" in kw or "checked" in kw Self.tag_configure("checked", image=self.im_checked)ĭef insert(self, parent, index, iid=None, **kw): Self.tag_configure("tristate", image=self.im_tristate) Self.tag_configure("unchecked", image=self.im_unchecked) Self.im_tristate = tk.PhotoImage(file='tristate.png') Self.im_unchecked = tk.PhotoImage(file='unchecked.png')

Self.im_checked = tk.PhotoImage(file='checked.png') # checkboxes are implemented with pictures The checkbox, you cannot add an image to the item. The checkboxes are done via the image attribute of the item, so to keep Treeview widget with checkboxes left of each item. I made a treeview class with checkboxes inheriting ttk.Treeview, but the checkboxes are not ttk.Checkbutton but images of checked, unchecked and tristate checkboxes.
