├── README.md └── SampleCode.py /README.md: -------------------------------------------------------------------------------- 1 | # TreeViewHorizontalScrollbar 2 | Horizontal scrollbar for ttk Treeview widget 3 | 4 | This code is based on http://www.tkdocs.com/tutorial/grid.html, and I successively implemented the version of TreeView combined horizontal scrollbar. 5 | 6 | See the image below for the excution result: 7 | ![alt text](https://i.stack.imgur.com/J8vPu.png) 8 | -------------------------------------------------------------------------------- /SampleCode.py: -------------------------------------------------------------------------------- 1 | try: 2 | from tkinter import * 3 | from tkinter import ttk 4 | except ImportError: 5 | from Tkinter import * 6 | from Tkinter import ttk 7 | 8 | root = Tk() 9 | 10 | content = ttk.Frame(root, padding=(3,3,12,12)) 11 | 12 | # initialize a TreeView 13 | myTreeView = ttk.Treeview(content) 14 | myTreeView["columns"] = ("Index", "Value", "Price", "LAST_PRICE") 15 | myTreeView.column("Index", stretch=False, width=150) 16 | myTreeView.column("Value", stretch=False, width=100) 17 | myTreeView.column("Price", stretch=False, width=100) 18 | myTreeView.column("LAST_PRICE", stretch=False, width=100) 19 | myTreeView.heading("Index", text="Index") 20 | myTreeView.heading("Value", text="Value") 21 | myTreeView.heading("Price", text="Price") 22 | myTreeView.heading("LAST_PRICE", text="Last Price") 23 | 24 | # attach a Horizontal (x) scrollbar to the frame 25 | treeXScroll = ttk.Scrollbar(content, orient=HORIZONTAL) 26 | treeXScroll.configure(command=myTreeView.xview) 27 | myTreeView.configure(xscrollcommand=treeXScroll.set) 28 | 29 | # initialize the Label and Entry 30 | namelbl = ttk.Label(content, text="Name") 31 | name = ttk.Entry(content) 32 | 33 | # initialize Checkbuttons 34 | onevar = BooleanVar() 35 | twovar = BooleanVar() 36 | threevar = BooleanVar() 37 | onevar.set(True) 38 | twovar.set(False) 39 | threevar.set(True) 40 | one = ttk.Checkbutton(content, text="One", variable=onevar, onvalue=True) 41 | two = ttk.Checkbutton(content, text="Two", variable=twovar, onvalue=True) 42 | three = ttk.Checkbutton(content, text="Three", variable=threevar, onvalue=True) 43 | 44 | # initialize Buttons 45 | ok = ttk.Button(content, text="Okay") 46 | cancel = ttk.Button(content, text="Cancel") 47 | 48 | # set position of all above objects by grid 49 | content.grid(column=0, row=0, sticky=(N, S, E, W)) 50 | myTreeView.grid(column=0, row=0, columnspan=3, rowspan=2, sticky=(N, S, E, W)) 51 | treeXScroll.grid(column=0, row=3, columnspan=3, sticky=W + E) 52 | namelbl.grid(column=3, row=0, columnspan=2, sticky=(N, W), padx=5) 53 | name.grid(column=3, row=1, columnspan=2, sticky=(N, E, W), pady=5, padx=5) 54 | one.grid(column=0, row=4) 55 | two.grid(column=1, row=4) 56 | three.grid(column=2, row=4) 57 | ok.grid(column=3, row=4) 58 | cancel.grid(column=4, row=4) 59 | 60 | # Handling Resize 61 | root.columnconfigure(0, weight=1) 62 | root.rowconfigure(0, weight=1) 63 | content.columnconfigure(0, weight=3) 64 | content.columnconfigure(1, weight=3) 65 | content.columnconfigure(2, weight=3) 66 | content.columnconfigure(3, weight=1) 67 | content.columnconfigure(4, weight=1) 68 | content.rowconfigure(1, weight=1) 69 | 70 | # run UI 71 | root.mainloop() 72 | --------------------------------------------------------------------------------