python tkinter Treeview 事件绑定

时间:2021-07-26 05:35:09
def trefun(event):
sels= event.widget.selection()#event.widget获取Treeview对象,调用selection获取选择对象名称
for idx in sels:
print tv.item(idx)["text"]
print "" if __name__ == '__main__':
global tv
_dex = dex("classes.dex")
_strs = _dex.getStrings() tp = Tk()
tv = ttk.Treeview(tp)
tv.grid(row = 0, column = 0)
scb= ttk.Scrollbar(tp, command = tv.yview)
tv.config(yscroll = scb.set)
scb.grid(row = 0, column = 1, sticky = "ns")
txt= Text(tp)
txt.grid(row = 0, column = 2)
tv.bind("<<TreeviewSelect>>", trefun) rtnode=tv.insert("",0,"dex",text="dex",values=(""))
apknode=tv.insert(rtnode,1,"apk信息",text="apk信息",values=(""))
strsnode=tv.insert(apknode, 2,"strings",text="strings",values=("")) dexclsnode=tv.insert(rtnode,1,"dexclasses",text="dexclasses",values=("")) strslen = len(_strs)
for i in xrange(0,strslen):
tv.insert(strsnode, -1,strslen - i,text=_strs[i],values=("")) tp.mainloop()

事件:

The Treeview widget generates the following virtual events.

event description
<<TreeviewSelect>> Generated whenever the selection changes.
<<TreeviewOpen>> Generated just before settings the focus item to open=True.
<<TreeviewClose>> Generated just after setting the focus item to open=False.
    tv.bind("<<TreeviewSelect>>", trefun)