Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
- # 2017.01.26
- # http://stackoverflow.com/questions/41877848/python-treeview-scrollbar
- # Tkinter - TreeView with Scrollbar
- from tkinter import ttk
- import tkinter as tk
- data = [
- ('L01', ('Big01', 'Best', 1)),
- ('L02', ('Big02', 'Best', 10)),
- ('L03', ('Big03', 'Best', 100)),
- ('L04', ('Big04', 'Best', 1000)),
- ('L05', ('Big05', 'Best', 10000)),
- ('L06', ('Big06', 'Best', 100000)),
- ('L07', ('Big07', 'Best', 1)),
- ('L08', ('Big08', 'Best', 10)),
- ('L09', ('Big09', 'Best', 100)),
- ('L10', ('Big10', 'Best', 1000)),
- ('L11', ('Big11', 'Best', 10000)),
- ('L12', ('Big12', 'Best', 100000)),
- ]
- win = tk.Tk()
- win.minsize(width=400, height=400)
- #win.resizable(width=0, height=0)
- frame = tk.Frame(win)
- frame.place(x=30, y=95)
- tree = ttk.Treeview(frame, selectmode='browse')
- tree.pack(side='left')
- vsb = ttk.Scrollbar(frame, orient='vertical', command=tree.yview)
- vsb.pack(side='right', fill='y')
- tree.configure(yscrollcommand=vsb.set)
- tree['columns'] = ('1', '2', '3')
- tree['show'] = 'headings'
- tree.column('1', width=100, anchor='w')
- tree.column('2', width=100, anchor='c')
- tree.column('3', width=100, anchor='e')
- tree.heading('1', text='Account')
- tree.heading('2', text='Type')
- tree.heading('3', text='Value')
- for txt, val in data:
- tree.insert('', 'end', text=txt, values=val)
- win.mainloop()
Add Comment
Please, Sign In to add comment