class TestWindow(Tk): def __init__(self): super().__init__() # Set the window parameters self.wm_title("Test Window") self.wm_geometry("800x600") self._nb = Notebook(self) self._nb.pack(fill=BOTH, expand=1) # Add the ScrollableTreeview self.STV = ScrollableTreeview( self._nb, columns=('first','second'), headers={ '#0':'Default', 'first':{'text':'First'}, 'second':{'text':'Second'} } ) self._nb.add(self.STV, text="Scrollable Treeview") iid = self.STV.insert('', 'end', text='Root Node') self.STV.insert(iid, 'end', text='Child 1') self.STV.insert(iid, 'end', text='Child 2')
def __init__(self, parentFrame, width, height, listtype): ScrollableTreeview.__init__(self, parentFrame, width=width, height=height) self.listtype = listtype self.treeview.configure(selectmode='browse', columns=self.columnsOrder) self.treeview['show'] = 'headings' # Hide the first column self.treeview.bind('<<TreeviewSelect>>', self.onCardSelection) # Display card info when an item is selected self.treeview.bind('<Double-1>', self.onDoubleClick) # This handles a double click on an already selected card, onCardSelection() handles this for unselected cards # Set up all the columns properly for columnName in self.columnsOrder: columnDisplayData = self.columnsDisplayData[columnName] displayname = columnDisplayData['displayname'] if 'displayname' in columnDisplayData else columnName.capitalize() # On heading click, sort the column by that value. Copy the column name into a local lambda var, otherwise you can only sort by the last column self.treeview.heading(columnName, text=displayname, command=lambda col=columnName: self.sortByColumn(col, False)) self.treeview.column(columnName, **self.columnTypeInfo[columnDisplayData['type']])