Eu li que você pode colocar a barra de rolagem à ESQUERDA no gerenciador de layout .pack(), mas não consigo encontrar uma solução funcional para o gerenciador de layout .grid(). A descrição em meu livro diz que devo usar sticky = 'nsw'
para localização. Então tentei movê-lo para a esquerda, veja meu exemplo.
Isso não tem nenhum efeito:
import tkinter as tk
from tkinter import ttk
from pathlib import Path
root = tk.Tk()
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
paths = Path('.').glob('**/*')
tv = ttk.Treeview(root, columns=['size','modified'], selectmode=None)
tv.heading('#0', text='Name')
tv.heading('size', text='Size', anchor='center')
tv.heading('modified', text='Modifies', anchor='center')
tv.column('#0', stretch = True, anchor='w')
tv.column('size', width=100, anchor='center')
tv.column('modified',anchor='center')
tv.grid_rowconfigure(0, weight=1)
tv.grid_columnconfigure(0, weight=1)
tv.grid(row=0, column=0, sticky='nsew')
#tv.pack(expand=True, fill='both')
for path in paths:
meta = path.stat()
parent = str(path.parent)
if parent == '.':
parent = ''
tv.insert(parent, 'end', iid=str(path), text=str(path.name), values=[meta.st_size, meta.st_mtime])
scrollbar = ttk.Scrollbar(root, orient=tk.VERTICAL, command=tv.yview)
tv.configure(yscrollcommand=scrollbar.set)
scrollbar.grid(row=0, column=1, sticky='nse') #scrollbar goes not to the left!
root.mainloop()
No treeview não é possÃvel localizar a barra de rolagem no lado ESQUERDO da janela?
Se você alterar
tv
a coluna de para 1 escrollbar
para 0, ele fará o que você deseja