获取树视图选择发生的顺序?
Get the order in which a treeviews selection occured?
以下代码创建一个树视图,用虚拟数据填充它,并在有变化时打印出选择:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
myTree = ttk.Treeview(root)
myTree.grid()
#Dummy Data
for n, i in enumerate(['get','the','index','order']):
myTree.insert(parent = "", index = "end", id = n, text = i)
def printSelected(*args):
print(myTree.selection())
myTree.bind("<<TreeviewSelect>>", printSelected)
root.mainloop()
目前它按排序顺序吐出选择,如何以反映选择方式的方式获得选择?
例子:树视图被选中的顺序是4-2-3-1
输出:1-2-3-4
期望输出:4-2-3-1
How can I get the selection in a way that reflects how it was selected?
树视图不提供这样做的能力。您必须添加自己的绑定来跟踪项目的选择顺序。
以下代码创建一个树视图,用虚拟数据填充它,并在有变化时打印出选择:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
myTree = ttk.Treeview(root)
myTree.grid()
#Dummy Data
for n, i in enumerate(['get','the','index','order']):
myTree.insert(parent = "", index = "end", id = n, text = i)
def printSelected(*args):
print(myTree.selection())
myTree.bind("<<TreeviewSelect>>", printSelected)
root.mainloop()
目前它按排序顺序吐出选择,如何以反映选择方式的方式获得选择?
例子:树视图被选中的顺序是4-2-3-1
输出:1-2-3-4
期望输出:4-2-3-1
How can I get the selection in a way that reflects how it was selected?
树视图不提供这样做的能力。您必须添加自己的绑定来跟踪项目的选择顺序。