furas

Python - tkinter - treeview & scrollbar

Jan 26th, 2017 (edited)
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
  2. # 2017.01.26
  3. # http://stackoverflow.com/questions/41877848/python-treeview-scrollbar
  4.  
  5. # Tkinter - TreeView with Scrollbar
  6.  
  7. from tkinter import ttk
  8. import tkinter as tk
  9.  
  10. data = [
  11.     ('L01', ('Big01', 'Best', 1)),
  12.     ('L02', ('Big02', 'Best', 10)),
  13.     ('L03', ('Big03', 'Best', 100)),
  14.     ('L04', ('Big04', 'Best', 1000)),
  15.     ('L05', ('Big05', 'Best', 10000)),
  16.     ('L06', ('Big06', 'Best', 100000)),
  17.     ('L07', ('Big07', 'Best', 1)),
  18.     ('L08', ('Big08', 'Best', 10)),
  19.     ('L09', ('Big09', 'Best', 100)),
  20.     ('L10', ('Big10', 'Best', 1000)),
  21.     ('L11', ('Big11', 'Best', 10000)),
  22.     ('L12', ('Big12', 'Best', 100000)),
  23. ]
  24.  
  25.  
  26. win = tk.Tk()
  27. win.minsize(width=400, height=400)
  28. #win.resizable(width=0, height=0)
  29.  
  30. frame = tk.Frame(win)
  31. frame.place(x=30, y=95)
  32.  
  33. tree = ttk.Treeview(frame, selectmode='browse')
  34. tree.pack(side='left')
  35.  
  36. vsb = ttk.Scrollbar(frame, orient='vertical', command=tree.yview)
  37. vsb.pack(side='right', fill='y')
  38.  
  39. tree.configure(yscrollcommand=vsb.set)
  40.  
  41. tree['columns'] = ('1', '2', '3')
  42. tree['show'] = 'headings'
  43.  
  44. tree.column('1', width=100, anchor='w')
  45. tree.column('2', width=100, anchor='c')
  46. tree.column('3', width=100, anchor='e')
  47.  
  48. tree.heading('1', text='Account')
  49. tree.heading('2', text='Type')
  50. tree.heading('3', text='Value')
  51.  
  52. for txt, val in data:
  53.     tree.insert('', 'end', text=txt, values=val)
  54.  
  55. win.mainloop()
Add Comment
Please, Sign In to add comment