Reputation: 55
I've imitated a table widget using treeview in Tkinter. And add a scroll bar linked to it. The question is as my data is add in the bottom by minute automatically, and I want the scroll at always scroll to the bottom. I know "text.see(END) "works perfectly in a text widget, but in my case, treeview widget didn't work. Thanks ahead!
from tkinter import *
from tkinter import ttk
root = Tk()
treedata = [('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 2'), ('column 1', 'column 222'), ('column 1', 'column 2')]
column_names = ("heading1", "heading2")
scrollbar = Scrollbar(root)
scrollbar.pack(side="right", fill="y")
tree = ttk.Treeview(root, columns = column_names, yscrollcommand = scrollbar.set)
for x in treedata:
tree.insert('', 'end', values =x)
for col in column_names:
tree.heading(col, text = col)
scrollbar.config(command=tree.yview)
tree.pack()
#tree.see(END)
root.mainloop()
Upvotes: 2
Views: 6264
Reputation: 16169
You can use tree.yview_moveto(1)
to display the bottom of the table. The yview_moveto
method takes as argument the fraction of the total (scrollable) widget height that you want to be off-screen to the top.
So, yview_moveto(0)
will display the top part of the table, yview_moveto(1)
the bottom part and yview_moveto(0.5)
will adjust the display so that the top half of the widget is hidden.
Upvotes: 7