Python ttk.Treeview() Examples

The following are 15 code examples for showing how to use ttk.Treeview(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module ttk , or try the search function .

Example 1
Project: pydiff   Author: yebrahim   File: mainwindow_ui.py    License: MIT License 7 votes vote down vote up
def create_file_treeview(self):
        self.fileTreeView = Treeview(self.main_window)
        self.fileTreeYScrollbar = Scrollbar(self.main_window, orient='vertical', command=self.fileTreeView.yview)
        self.fileTreeXScrollbar = Scrollbar(self.main_window, orient='horizontal', command=self.fileTreeView.xview)
        self.fileTreeView.configure(yscroll=self.fileTreeYScrollbar.set, xscroll=self.fileTreeXScrollbar.set)

        self.fileTreeView.grid(row=self.fileTreeRow, column=self.fileTreeCol, sticky=NS, rowspan=3)
        self.fileTreeYScrollbar.grid(row=self.fileTreeRow, column=self.fileTreeScrollbarCol, sticky=NS, rowspan=3)
        self.fileTreeXScrollbar.grid(row=self.horizontalScrollbarRow, column=self.fileTreeCol, sticky=EW)

        self.fileTreeView.tag_configure('red', background=self.redColor)
        self.fileTreeView.tag_configure('green', background=self.greenColor)
        self.fileTreeView.tag_configure('yellow', background=self.yellowColor)
        self.fileTreeView.tag_configure('purpleLight', background=self.purpleLight)

        # hide it until needed
        self.fileTreeView.grid_remove()
        self.fileTreeYScrollbar.grid_remove()
        self.fileTreeXScrollbar.grid_remove()

    # Text areas 
Example 2
Project: ms_deisotope   Author: mobiusklein   File: view.py    License: Apache License 2.0 6 votes vote down vote up
def configure_treeview(self):
        self.treeview = ttk.Treeview(self)
        self.treeview['columns'] = ["id", "time", 'ms_level', 'precursor_mz', 'precursor_charge', 'activation']
        self.treeview.grid(row=2, column=0, sticky=tk.S + tk.W + tk.E + tk.N)

        self.treeview_scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.treeview.yview)
        self.treeview_scrollbar.grid(row=2, column=0, sticky=tk.S + tk.E + tk.N)
        self.treeview.configure(yscrollcommand=self.treeview_scrollbar.set)

        self.treeview.heading('id', text="Scan ID")
        self.treeview.heading('#0', text='Index')
        self.treeview.heading("time", text='Time (min)')
        self.treeview.heading("ms_level", text='MS Level')
        self.treeview.heading("precursor_mz", text='Precursor M/Z')
        self.treeview.heading("precursor_charge", text='Precursor Z')
        self.treeview.heading("activation", text='Activation')
        self.treeview.column("#0", width=75)
        self.treeview.column("ms_level", width=75)
        self.treeview.column("time", width=75)
        self.treeview.column("precursor_mz", width=100)
        self.treeview.column("precursor_charge", width=100)
        self.treeview.bind("<<TreeviewSelect>>", self.on_row_click) 
Example 3
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def set_treeview_properties(self, element):
        """
        Set the information text for the Treeview *element*.
        """
        # set class property
        self.treeview.set(element.treeview_id, "class", element.treeview_class_name)

        # add the check marks for barcodes/variants
        if "variants" in element.labels:
            self.treeview.set(element.treeview_id, "variants", u"\u2713")
        else:
            self.treeview.set(element.treeview_id, "variants", "")
        if "barcodes" in element.labels:
            self.treeview.set(element.treeview_id, "barcodes", u"\u2713")
        else:
            self.treeview.set(element.treeview_id, "barcodes", "")

        self.treeview.set(element.treeview_id, "class", element.treeview_class_name) 
Example 4
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def populate_tree(self, element, parent_id=""):
        """
        Recursively populate the Treeview.

        Also populates the *id_cfgstrings*.
        """
        # insert into the Treeview
        element.treeview_id = self.treeview.insert(
            parent_id, "end", text=element.name, open=True
        )
        # add id-element pair to dictionary
        self.element_dict[element.treeview_id] = element
        # set information fields
        self.set_treeview_properties(element)

        # populate for children
        if element.children is not None:
            for child in element.children:
                self.populate_tree(child, parent_id=element.treeview_id) 
Example 5
Project: PCWG   Author: PCWG   File: grid_box.py    License: MIT License 6 votes vote down vote up
def _set_up_tree_widget(self):

        tree_container = ttk.Frame(self.container)

        tree_container.grid(row=0, column=0, sticky=tk.W+tk.E+tk.N+tk.S)

        #tree_container.pack(fill='both', expand=True)

        # create a treeview with dual scrollbars
        self.tree = ttk.Treeview(tree_container, columns=self.headers, show="headings")
        
        vsb = ttk.Scrollbar(tree_container, orient="vertical", command=self.tree.yview)
        hsb = ttk.Scrollbar(tree_container, orient="horizontal", command=self.tree.xview)

        self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
        self.tree.grid(column=0, row=0, sticky='nsew')

        vsb.grid(column=1, row=0, sticky='ns')
        hsb.grid(column=0, row=1, sticky='ew')

        tree_container.grid_columnconfigure(0, weight=1)
        tree_container.grid_rowconfigure(0, weight=1)

        self.tree.bind("<Double-1>", self.double_click) 
Example 6
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def setUp(self):
        support.root_deiconify()
        self.tv = ttk.Treeview(padding=0) 
Example 7
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Treeview(self.root, **kwargs) 
Example 8
Project: ProperTree   Author: corpnewt   File: plistwindow.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stackorder(self, root):
        """return a list of root and toplevel windows in stacking order (topmost is last)"""
        c = root.children
        s = root.tk.eval('wm stackorder {}'.format(root))
        L = [x.lstrip('.') for x in s.split()]
        return [(c[x] if x else root) for x in L]

    ###                                             ###
    # Converstion to/from Dict and Treeview Functions #
    ###                                             ### 
Example 9
Project: ProperTree   Author: corpnewt   File: plistwindow.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def remove_row(self,target=None):
        if target == None or isinstance(target, tk.Event):
            target = "" if not len(self._tree.selection()) else self._tree.selection()[0]
        if target in ("",self.get_root_node()):
            # Can't remove top level
            return
        parent = self._tree.parent(target)
        self.add_undo({
            "type":"remove",
            "cell":target,
            "from":parent,
            "index":self._tree.index(target)
        })
        self._tree.detach(target)
        # self._tree.delete(target) # Removes completely
        # Might include an undo function for removals, at least - tbd
        if not self.edited:
            self.edited = True
            self.title(self.title()+" - Edited")
        # Check if the parent was an array/dict, and update counts
        if parent == "":
            return
        if self.get_check_type(parent).lower() == "array":
            self.update_array_counts(parent)
        self.update_children(parent)
        self.alternate_colors()

    ###                          ###
    # Treeview Data Helper Methods #
    ###                          ### 
Example 10
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def menu_selectall(self):
        """
        Add all elements in the Treeview to the selection.
        """
        for k in self.element_dict.keys():
            self.treeview.selection_add(k) 
Example 11
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def delete_element(self, tree_id):
        """
        Delete element with Treeview id *tree_id* from the tree, from the element 
        dictionary, and from the associated data structure. Recursively 
        deletes all children of *tree_id*.

        The tree should be refreshed using :py:meth:`refresh_tree` after 
        each deletion. This is the responsibility of the caller.

        """
        # if self.treeview.exists(tree_id):
        if tree_id in self.element_dict:
            # recursively delete children
            if self.element_dict[tree_id].children is not None:
                for child in self.element_dict[tree_id].children:
                    self.delete_element(child.treeview_id)

            # check if deleting the root element
            if self.root_element.treeview_id == tree_id:
                # clear the root element
                self.root_element = None
            else:
                try:
                    # remove the element from its parent's list of children
                    self.element_dict[tree_id].parent.remove_child_id(tree_id)
                except AttributeError:
                    raise AttributeError("Non-root element lacks proper parent")

            # delete the element from the dictionary
            del self.element_dict[tree_id] 
Example 12
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def refresh_treeview(self):
        """
        Clears the Treeview and repopulates it with the current contents of the tree.
        """
        # clear the entries in the Treeview
        for x in self.treeview.get_children():
            self.treeview.delete(x)

        # clear the id-element dictionary
        # elements may be given new id's after repopulation
        self.element_dict.clear()

        # repopulate
        if self.root_element is not None:
            self.populate_tree(self.root_element) 
Example 13
Project: Enrich2   Author: FowlerLab   File: configurator.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_selected_elements(self):
        """
        Returns a list of elements that are currently selected in the Treeview.

        If no elements are selected, it returns an empty list.
        """
        return [self.get_element(x) for x in self.treeview.selection()] 
Example 14
Project: PokemonGo-DesktopMap   Author: mchristopher   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Treeview(self.root, **kwargs) 
Example 15
Project: sqlite_bro   Author: stonebig   File: sqlite_bro.py    License: MIT License 4 votes vote down vote up
def __init__(self):
        """create a tkk graphic interface with a main window tk_win"""
        self.__version__ = '0.9.1'
        self._title = "2019-06-16a : 'Support un-named Tabs!'"
        self.conn = None  # Baresql database object
        self.database_file = ""
        self.tk_win = Tk()
        self.tk_win.title('A graphic SQLite Client in 1 Python file')
        self.tk_win.option_add('*tearOff', FALSE)   # hint of tk documentation
        self.tk_win.minsize(600, 200)               # minimal size

        self.font_size = 10
        self.font_wheight = 0
        self.initialdir = "."
        # With a Menubar and Toolbar
        self.create_menu()
        self.create_toolbar()

        # Create style "ButtonNotebook"
        self.create_style()
        # Initiate Drag State
        self.state_drag = False
        self.state_drag_index = 0

        # With a Panedwindow of two frames: 'Database' and 'Queries'
        p = ttk.Panedwindow(self.tk_win, orient=HORIZONTAL)
        p.pack(fill=BOTH, expand=1)

        f_database = ttk.Labelframe(p, text='Databases', width=200, height=100)
        p.add(f_database)
        f_queries = ttk.Labelframe(p, text='Queries', width=200, height=100)
        p.add(f_queries)

        # build tree view 't' inside the left 'Database' Frame
        self.db_tree = ttk.Treeview(f_database, displaycolumns=[],
                                    columns=("detail", "action"))
        self.db_tree.tag_configure("run")
        self.db_tree.pack(fill=BOTH, expand=1)

        # create a  notebook 'n' inside the right 'Queries' Frame
        self.n = NotebookForQueries(self.tk_win, f_queries, [])

        # Bind keyboard shortcuts
        self.tk_win.bind('<F9>', self.run_tab)