我想找到一个功能,可以控制与滚动条树视图 是否显示更新到屏幕
因为我经常更改treeview内容导致效率下降,所以我只想让treeview 当我需要的时候
我做了一些研究,说tkinter只在事件触发时更新 ,但我使用线程更改Threeview内容也会导致屏幕更新
from tkinter.ttk import *
from tkinter import *
root = Tk()
root.geometry('800x800')
root.bind('<Escape>', lambda x:root.destroy() )
class Run_item_Tree(Frame):
def __init__(self, roots):
Frame.__init__(self, roots)
t = Treeview(self, selectmode=NONE, height=10)
self.t = t
t["columns"] = ("1", "2")
t['show'] = 'headings'
t.column("1", width=100, anchor='c')
t.column("2", width=50, anchor='c')
t.heading("1", text="Title")
t.heading("2", text="UL")
t.pack(fill =BOTH,side =LEFT)
vsb = Scrollbar(self, orient="vertical", command=t.yview)
vsb.pack(fill = Y,side = RIGHT)
self.vsb = vsb
t.configure(yscrollcommand=vsb.set)
self.pack()
a = Run_item_Tree(root)
item_num = 4000
for i in range(item_num):
a.t.insert('',index=END,text = i,values = (i,i+1,i+2,i+4),tags=('pass',))
count = 0
def update_test():
global count
#a.t.yview_moveto(count/item_num)
a.t.item(a.t.get_children()[0],values = (count,count+1,count+2,count+4) )
count= (count+1)%item_num
root.after(100, update_test)
btn = Button(root,text='update/unupdate',command=lambda : SomeFunction())
btn.pack()
root.after(100,update_test)
root.mainloop()
要控制
Treeview
更新,需要有一个单独的函数来处理update_test
函数是否被调用您正在使用
.after
,这很好,这意味着您可以使用.after_cancel
来停止循环代码需要重新构造,但我将让您自己进行重新构造,
functions
会更好,因为您已经定义了class
中的methods
相关问题 更多 >
编程相关推荐