Python tkinter.ttk.Treeview() Examples

The following are 30 code examples of tkinter.ttk.Treeview(). 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 also want to check out all available functions/classes of the module tkinter.ttk , or try the search function .
Example #1
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 8 votes vote down vote up
def __init__(self, master=None, **kw):
        ttk.Treeview.__init__(self, master, **kw)

        self._curfocus = None
        self._inplace_widgets = {}
        self._inplace_widgets_show = {}
        self._inplace_vars = {}
        self._header_clicked = False
        self._header_dragged = False

        # Wheel events?
        self.bind('<<TreeviewSelect>>', self.check_focus)
        self.bind('<4>', lambda e: self.after_idle(self.__updateWnds))
        self.bind('<5>', lambda e: self.after_idle(self.__updateWnds))
        self.bind('<KeyRelease>', self.check_focus)
        self.bind('<Home>', functools.partial(self.__on_key_press, 'Home'))
        self.bind('<End>', functools.partial(self.__on_key_press, 'End'))
        self.bind('<Button-1>', self.__on_button1)
        self.bind('<ButtonRelease-1>', self.__on_button1_release)
        self.bind('<Motion>', self.__on_mouse_motion)
        self.bind('<Configure>', lambda e: self.after_idle(self.__updateWnds)) 
Example #2
Source File: groups.py    From tk_tools with MIT License 7 votes vote down vote up
def __place_widgets(self):
        # header frame and its widgets
        hframe = ttk.Frame(self)
        lbtn = ttk.Button(hframe,
                          style='L.TButton',
                          command=self._prev_month)
        rbtn = ttk.Button(hframe,
                          style='R.TButton',
                          command=self._next_month)
        self._header = ttk.Label(hframe, width=15, anchor='center')
        # the calendar
        self._calendar = ttk.Treeview(self, show='',
                                      selectmode='none', height=7)

        # pack the widgets
        hframe.pack(in_=self, side='top', pady=4, anchor='center')
        lbtn.grid(in_=hframe)
        self._header.grid(in_=hframe, column=1, row=0, padx=12)
        rbtn.grid(in_=hframe, column=2, row=0)
        self._calendar.pack(in_=self, expand=1, fill='both', side='bottom') 
Example #3
Source File: mainwindow_ui.py    From pydiff with 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 #4
Source File: hr_menu.py    From hackerrank with The Unlicense 6 votes vote down vote up
def show_data(data):
    # Setup the root UI
    root = tk.Tk()
    root.title("JSON viewer")
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)

    # Setup the Frames
    tree_frame = ttk.Frame(root, padding="3")
    tree_frame.grid(row=0, column=0, sticky=tk.NSEW)

    # Setup the Tree
    tree = ttk.Treeview(tree_frame, columns='Values')
    tree.tag_configure("d", foreground='blue')
    tree.column('Values', width=100)
    tree.heading('Values', text='Values')
    json_tree(tree, '', data)
    tree.pack(fill=tk.BOTH, expand=1)

    # Limit windows minimum dimensions
    root.update_idletasks()
    root.minsize(500, 500)
    raise_app()

    root.mainloop() 
Example #5
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def yview(self, *args):
        """Update inplace widgets position when doing vertical scroll"""
        self.after_idle(self.__updateWnds)
        ttk.Treeview.yview(self, *args) 
Example #6
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def yview_scroll(self, number, what):
        self.after_idle(self.__updateWnds)
        ttk.Treeview.yview_scroll(self, number, what) 
Example #7
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete(self, *items):
        self.after_idle(self.__updateWnds)
        ttk.Treeview.delete(self, *items) 
Example #8
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def xview_scroll(self, number, what):
        self.after_idle(self.__updateWnds)
        ttk.Treeview.xview_scroll(self, number, what) 
Example #9
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def __init__(self, master=None, **kw):
        ttk.Treeview.__init__(self, master, **kw)
        self._inplace_widget = None
        self._inplace_var = None
        self._inplace_item = '' 
Example #10
Source File: views.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def __init__(self, parent, callbacks, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.callbacks = callbacks
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        # create treeview
        self.treeview = ttk.Treeview(
            self,
            columns=list(self.column_defs.keys())[1:],
            selectmode='browse'
        )

        # configure scrollbar for the treeview
        self.scrollbar = ttk.Scrollbar(
            self,
            orient=tk.VERTICAL,
            command=self.treeview.yview
        )
        self.treeview.configure(yscrollcommand=self.scrollbar.set)
        self.treeview.grid(row=0, column=0, sticky='NSEW')
        self.scrollbar.grid(row=0, column=1, sticky='NSW')

        # Configure treeview columns
        for name, definition in self.column_defs.items():
            label = definition.get('label', '')
            anchor = definition.get('anchor', self.default_anchor)
            minwidth = definition.get('minwidth', self.default_minwidth)
            width = definition.get('width', self.default_width)
            stretch = definition.get('stretch', False)
            self.treeview.heading(name, text=label, anchor=anchor)
            self.treeview.column(name, anchor=anchor, minwidth=minwidth,
                                 width=width, stretch=stretch)

        self.treeview.bind('<<TreeviewOpen>>', self.on_open_record) 
Example #11
Source File: chapter8_03.py    From Tkinter-GUI-Application-Development-Cookbook with MIT License 6 votes vote down vote up
def __init__(self, path):
        super().__init__()
        self.title("Ttk Treeview")

        columns = ("#1", "#2", "#3")
        self.tree = ttk.Treeview(self, show="headings", columns=columns)
        self.tree.heading("#1", text="Last name")
        self.tree.heading("#2", text="First name")
        self.tree.heading("#3", text="Email")
        ysb = ttk.Scrollbar(self, orient=tk.VERTICAL, command=self.tree.yview)
        self.tree.configure(yscroll=ysb.set)

        with open("contacts.csv", newline="") as f:
            for contact in csv.reader(f):
                self.tree.insert("", tk.END, values=contact)
        self.tree.bind("<<TreeviewSelect>>", self.print_selection)

        self.tree.grid(row=0, column=0)
        ysb.grid(row=0, column=1, sticky=tk.N + tk.S)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1) 
Example #12
Source File: chapter8_04.py    From Tkinter-GUI-Application-Development-Cookbook with MIT License 6 votes vote down vote up
def __init__(self, path):
        super().__init__()
        self.title("Ttk Treeview")

        abspath = os.path.abspath(path)
        self.nodes = {}
        self.tree = ttk.Treeview(self)
        self.tree.heading("#0", text=abspath, anchor=tk.W)
        ysb = ttk.Scrollbar(self, orient=tk.VERTICAL,
                            command=self.tree.yview)
        xsb = ttk.Scrollbar(self, orient=tk.HORIZONTAL,
                            command=self.tree.xview)
        self.tree.configure(yscroll=ysb.set, xscroll=xsb.set)

        self.tree.grid(row=0, column=0, sticky=tk.N + tk.S + tk.E + tk.W)
        ysb.grid(row=0, column=1, sticky=tk.N + tk.S)
        xsb.grid(row=1, column=0, sticky=tk.E + tk.W)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

        self.tree.bind("<<TreeviewOpen>>", self.open_node)
        self.populate_node("", abspath) 
Example #13
Source File: gameobjects.py    From code-jam-5 with MIT License 6 votes vote down vote up
def upgrade_menu():
    upgrade_window = tk.Tk()
    upgrade_window.geometry('400x400+0+0')
    upgrade_window.title("Upgrades window")

    # Example tkinter treeview widget use
    tree = ttk.Treeview(upgrade_window)
    tree["columns"] = ("one", "two")
    tree.column("one", width=150)
    tree.column("two", width=100)
    tree.heading("one", text="column A")
    tree.heading("two", text="column B")
    tree.insert("", 0, text="Line 1", values=("1A", "1b"))
    tree.insert("", "end", text="sub dir 2", values=("2A", "2B"))
    # insert sub-item, method 1
    id2 = tree.insert("", "end", "dir2", text="Dir 2")
    tree.insert(id2, "end", text="sub dir 2-1", values=("2A", "2B"))
    tree.insert(id2, "end", text="sub dir 2-2", values=("2A-2", "2B-2"))
    # insert sub-item, method 2
    tree.insert("", "end", "dir3", text="Dir 3")
    tree.insert("dir3", "end", text=" sub dir 3", values=("3A", "3B"))
    tree.pack()

    upgrade_window.mainloop() 
Example #14
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def xview(self, *args):
        """Update inplace widgets position when doing horizontal scroll"""
        self.after_idle(self.__updateWnds)
        ttk.Treeview.xview(self, *args) 
Example #15
Source File: EditableTreeview.py    From PyEngine3D with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def xview_moveto(self, fraction):
        self.after_idle(self.__updateWnds)
        ttk.Treeview.xview_moveto(self, fraction) 
Example #16
Source File: view.py    From ms_deisotope with 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 #17
Source File: pyjsonviewer.py    From PyJSONViewer with MIT License 6 votes vote down vote up
def __init__(self, master, json_path=None, initial_dir="~/"):
        super().__init__(master)
        self.master = master
        self.tree = ttk.Treeview(self)
        self.create_widgets()
        self.sub_win = None
        self.initial_dir = initial_dir
        self.search_box = None
        self.bottom_frame = None
        self.search_box = None
        self.search_label = None

        if json_path:
            self.set_table_data_from_json(json_path) 
Example #18
Source File: outline.py    From thonny with MIT License 6 votes vote down vote up
def _init_widgets(self):
        # init and place scrollbar
        self.vert_scrollbar = SafeScrollbar(self, orient=tk.VERTICAL)
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW)

        # init and place tree
        self.tree = ttk.Treeview(self, yscrollcommand=self.vert_scrollbar.set)
        self.tree.grid(row=0, column=0, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.tree.yview

        # set single-cell frame
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        # init tree events
        self.tree.bind("<<TreeviewSelect>>", self._on_select, True)
        self.tree.bind("<Map>", self._update_frame_contents, True)

        # configure the only tree column
        self.tree.column("#0", anchor=tk.W, stretch=True)
        # self.tree.heading('#0', text='Item (type @ line)', anchor=tk.W)
        self.tree["show"] = ("tree",)

        self._class_img = get_workbench().get_image("outline-class")
        self._method_img = get_workbench().get_image("outline-method") 
Example #19
Source File: table.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def cget(self, key):
        """
        Query widget option.

        :param key: option name
        :type key: str
        :return: value of the option

        To get the list of options for this widget, call the method :meth:`~Table.keys`.
        """
        if key == 'sortable':
            return self._sortable
        elif key == 'drag_cols':
            return self._drag_cols
        elif key == 'drag_rows':
            return self._drag_rows
        else:
            return ttk.Treeview.cget(self, key) 
Example #20
Source File: display_analysis.py    From faceswap with GNU General Public License v3.0 6 votes vote down vote up
def tree_columns(self):
        """ Add the columns to the totals tree-view """
        logger.debug("Adding Treeview columns")
        columns = (("session", 40, "#"),
                   ("start", 130, None),
                   ("end", 130, None),
                   ("elapsed", 90, None),
                   ("batch", 50, None),
                   ("iterations", 90, None),
                   ("rate", 60, "EGs/sec"))
        self.tree["columns"] = [column[0] for column in columns]

        for column in columns:
            text = column[2] if column[2] else column[0].title()
            logger.debug("Adding heading: '%s'", text)
            self.tree.heading(column[0], text=text)
            self.tree.column(column[0], width=column[1], anchor=tk.E, minwidth=40)
        self.tree.column("#0", width=40)
        self.tree.heading("#0", text="Graphs")

        return [column[0] for column in columns] 
Example #21
Source File: table.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def heading(self, column, option=None, **kw):
        """
        Query or modify the heading options for the specified column.

        If `kw` is not given, returns a dict of the heading option values. If
        `option` is specified then the value for that option is returned.
        Otherwise, sets the options to the corresponding values.

        :param text: text to display in the column heading
        :type text: str
        :param image: image to display to the right of the column heading
        :type image: PhotoImage
        :param anchor: "n", "ne", "e", "se", "s", "sw", "w", "nw", or "center":
                       alignement of the heading text
        :type anchor: str
        :param command: callback to be invoked when the heading label is pressed.
        :type command: function
        """
        if kw:
            # Set the default image of the heading to the drag icon
            kw.setdefault("image", self._im_drag)
            self._visual_drag.heading(ttk.Treeview.column(self, column, 'id'), option, **kw)
        return ttk.Treeview.heading(self, column, option, **kw) 
Example #22
Source File: table.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def item(self, item, option=None, **kw):
        """
        Query or modify the options for the specified item.

        If no options are given, a dict with options/values for the item is returned.
        If option is specified then the value for that option is returned.
        Otherwise, sets the options to the corresponding values as given by `kw`.
        
        :param text: item's label
        :type text: str
        :param image: image to be displayed on the left of the item's label
        :type image: PhotoImage
        :param values: values to put in the columns
        :type values: sequence
        :param open: whether the item's children should be displayed
        :type open: bool
        :param tags: list of tags associated with this item
        :type tags: sequence[str]
        """
        if kw:
            self._visual_drag.item(item, option, **kw)
        return ttk.Treeview.item(self, item, option, **kw) 
Example #23
Source File: table.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def set(self, item, column=None, value=None):
        """
        Query or set the value of given item.

        With one argument, return a dictionary of column/value pairs for the
        specified item. With two arguments, return the current value of the
        specified column. With three arguments, set the value of given column
        in given item to the specified value.

        :param item: item's identifier
        :type item: str
        :param column: column's identifier
        :type column: str, int or None
        :param value: new value
        """
        if value is not None:
            self._visual_drag.set(item, ttk.Treeview.column(self, column, 'id'), value)
        return ttk.Treeview.set(self, item, column, value) 
Example #24
Source File: checkboxtreeview.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def state(self, statespec=None):
        """
        Modify or inquire widget state.
        
        :param statespec: Widget state is returned if `statespec` is None, 
                          otherwise it is set according to the statespec 
                          flags and then a new state spec is returned 
                          indicating which flags were changed.
        :type statespec: None or sequence[str]
        """
        if statespec:
            if "disabled" in statespec:
                self.bind('<Button-1>', lambda e: 'break')
            elif "!disabled" in statespec:
                self.unbind("<Button-1>")
                self.bind("<Button-1>", self._box_click, True)
            return ttk.Treeview.state(self, statespec)
        else:
            return ttk.Treeview.state(self) 
Example #25
Source File: box.py    From synthesizer with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, app, master):
        super().__init__(master, text="Playlist", padding=4)
        self.app = app
        bf = ttk.Frame(self)
        ttk.Button(bf, text="Move to Top", width=11, command=self.do_to_top).pack()
        ttk.Button(bf, text="Move Up", width=11, command=self.do_move_up).pack()
        ttk.Button(bf, text="Move Down", width=11, command=self.do_move_down).pack()
        ttk.Button(bf, text="Remove", width=11, command=self.do_remove).pack()
        bf.pack(side=tk.LEFT, padx=4)
        sf = ttk.Frame(self)
        cols = [("title", 300), ("artist", 180), ("album", 180), ("length", 80)]
        self.listTree = ttk.Treeview(sf, columns=[col for col, _ in cols], height=10, show="headings")
        vsb = ttk.Scrollbar(orient="vertical", command=self.listTree.yview)
        self.listTree.configure(yscrollcommand=vsb.set)
        self.listTree.grid(column=1, row=0, sticky=tk.NSEW, in_=sf)
        vsb.grid(column=0, row=0, sticky=tk.NS, in_=sf)
        for col, colwidth in cols:
            self.listTree.heading(col, text=col.title())
            self.listTree.column(col, width=colwidth)
        sf.grid_columnconfigure(0, weight=1)
        sf.grid_rowconfigure(0, weight=1)
        sf.pack(side=tk.LEFT, padx=4) 
Example #26
Source File: table.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def _initialize_style(self):
        style = ttk.Style(self)
        style.layout('Table', style.layout('Treeview'))
        style.layout('Table.Heading',
                     [('Treeheading.cell', {'sticky': 'nswe'}),
                      ('Treeheading.border',
                       {'sticky': 'nswe',
                        'children': [('Treeheading.padding',
                                      {'sticky': 'nswe',
                                       'children': [('Treeheading.image', {'side': 'left', 'sticky': ''}),
                                                    ('Treeheading.text', {'sticky': 'we'})]})]})])
        config = style.configure('Treeview')
        if config:
            style.configure('Table', **config)
        config_heading = style.configure('Treeview.Heading')
        if config_heading:
            style.configure('Table.Heading', **config_heading)
        style_map = style.map('Treeview')
        # add noticeable disabled style
        fieldbackground = style_map.get('fieldbackground', [])
        fieldbackground.append(("disabled", '#E6E6E6'))
        style_map['fieldbackground'] = fieldbackground
        foreground = style_map.get('foreground', [])
        foreground.append(("disabled", 'gray40'))
        style_map['foreground'] = foreground
        background = style_map.get('background', [])
        background.append(("disabled", '#E6E6E6'))
        style_map['background'] = background
        style.map('Table', **style_map)

        style_map_heading = style.map('Treeview.Heading')
        style.map('Table.Heading', **style_map_heading) 
Example #27
Source File: plistwindow.py    From ProperTree with 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 #28
Source File: SymbolBrowser.py    From halucinator with GNU General Public License v3.0 5 votes vote down vote up
def create_gui_elements(self):
        '''
            Creates the elements in the GUI
        '''
        # Label for functions that are recorded
        self.table_funcs = Label(master=self.root, text="Functions")
        # self.table_funcs.config(width=400)

        # Tree of recording listings
        self.tree = ttk.Treeview(master=self.root)
        # self.tree.column('#0', minwidth=400)
        self.tree.bind('<Button-1>', self.on_func_click)
        self.create_recording_listing()

        # Label for diplaying recording details
        self.record_label = Label(master=self.root, text="Recorded")

        # Tree for displaying record details
        self.record_tree = ttk.Treeview(master=self.root,
                                        columns=("Type", "Name", "Size", "Before", "After"))
        self.record_tree.heading('#1', text='Type')
        self.record_tree.heading('#2', text='Name')
        self.record_tree.heading('#3', text='Size')
        self.record_tree.heading('#4', text='Entry Value')
        self.record_tree.heading('#5', text='Exit Value')
        self.record_tree.tag_configure('DIFF', background='light coral')
        self.set_layout() 
Example #29
Source File: box.py    From synthesizer with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, app, master):
        super().__init__(master, text="Search song", padding=4)
        self.app = app
        self.search_text = tk.StringVar()
        self.filter_choice = tk.StringVar(value="title")
        bf = ttk.Frame(self)
        ttk.Label(bf, text="Search for:").pack()
        e = ttk.Entry(bf, textvariable=self.search_text)
        e.bind("<Return>", self.do_search)
        e.bind("<KeyRelease>", self.on_key_up)
        self.search_job = None
        e.pack()
        ttk.Radiobutton(bf, text="title", value="title", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="artist", value="artist", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="album", value="album", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="year", value="year", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="genre", value="genre", variable=self.filter_choice, width=10).pack()
        ttk.Button(bf, text="Search", command=self.do_search).pack()
        ttk.Button(bf, text="Add all selected", command=self.do_add_selected).pack()
        bf.pack(side=tk.LEFT)
        sf = ttk.Frame(self)
        cols = [("title", 320), ("artist", 200), ("album", 200), ("year", 60), ("genre", 160), ("length", 80)]
        self.resultTreeView = ttk.Treeview(sf, columns=[col for col, _ in cols], height=16, show="headings")
        vsb = ttk.Scrollbar(orient="vertical", command=self.resultTreeView.yview)
        self.resultTreeView.configure(yscrollcommand=vsb.set)
        self.resultTreeView.grid(column=1, row=0, sticky=tk.NSEW, in_=sf)
        vsb.grid(column=0, row=0, sticky=tk.NS, in_=sf)
        for col, colwidth in cols:
            self.resultTreeView.heading(col, text=col.title(), command=lambda c=col: self.sortby(self.resultTreeView, c, 0))
            self.resultTreeView.column(col, width=colwidth)
        self.resultTreeView.bind("<Double-1>", self.on_doubleclick)
        sf.grid_columnconfigure(0, weight=1)
        sf.grid_rowconfigure(0, weight=1)
        sf.pack(side=tk.LEFT, padx=4) 
Example #30
Source File: TreeView.py    From python-in-practice with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, master=None, **kwargs):
        super().__init__(master)
        self.frame = self
        self.treeview = ttk.Treeview(self, **kwargs)
        self.xscrollbar = TkUtil.Scrollbar.Scrollbar(self,
                command=self.treeview.xview, orient=tk.HORIZONTAL)
        self.yscrollbar = TkUtil.Scrollbar.Scrollbar(self,
                command=self.treeview.yview, orient=tk.VERTICAL)
        self.treeview.configure(yscrollcommand=self.yscrollbar.set,
                xscrollcommand=self.xscrollbar.set)
        self.xscrollbar.grid(row=1, column=0, sticky=(tk.W, tk.E))
        self.yscrollbar.grid(row=0, column=1, sticky=(tk.N, tk.S))
        self.treeview.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, tk.E))
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)