滚动条覆盖数据

时间:2019-06-24 07:59:10

标签: python python-3.x tkinter

我的树视图数据的最后一行被底部滚动条覆盖

我到处都用Google搜索,没有找到答案

root = tk.Tk()
tree = ttk.Treeview(root)
scrollbar_horizontal = ttk.Scrollbar(tree, orient='horizontal', command=tree.xview)
scrollbar_vertical = ttk.Scrollbar(tree, orient='vertical', command=tree.yview)
scrollbar_horizontal.pack(side='bottom', fill='x')
scrollbar_vertical.pack(side='right', fill='y')
tree.configure(xscrollcommand=scrollbar_horizontal.set, yscrollcommand=scrollbar_vertical.set)

我不希望滚动条覆盖我的最后一行

我错过了一些东西。

What it looks like

1 个答案:

答案 0 :(得分:1)

您已将tree分配为滚动条的父级。将它们更改回root窗口,并改用grid

from tkinter import ttk
import tkinter as tk

root = tk.Tk()
tree = ttk.Treeview(root)
tree.grid(row=0,column=0)
scrollbar_vertical = ttk.Scrollbar(root, orient='vertical', command=tree.yview)
scrollbar_vertical.grid(row=0,column=1,sticky="ns")
scrollbar_horizontal = ttk.Scrollbar(root, orient='horizontal', command=tree.xview)
scrollbar_horizontal.grid(row=1,column=0,sticky="ew")
tree.configure(yscrollcommand=scrollbar_vertical.set,xscrollcommand=scrollbar_horizontal.set)

header = "ABCDEFG"
tree["columns"] = [i for i in header]

for i in range(len(header)):
    tree.column(header[i], width=100, minwidth=50, anchor="w",stretch=tk.NO)
    tree.heading(header[i], text=header[i], anchor='w')

for i in range(15):
    tree.insert("",0,values=[i for i in header])

root.mainloop()