CTRL+;treeview中的一个小部件-Python

CTRL+;treeview中的一个小部件-Python,python,tkinter,treeview,ctrl,Python,Tkinter,Treeview,Ctrl,请帮助我在treeview小部件tkinter python中使用ctrl+a键一次选择所有行。谢谢 import tkinter as tk from tkinter import ttk root = tk.Tk() cols = ('name','age') e = ttk.Treeview(root,columns=cols) for col in cols: e.heading(col, text=col) e.column(col,

请帮助我在treeview小部件tkinter python中使用ctrl+a键一次选择所有行。谢谢

import tkinter as tk
from tkinter import ttk


root = tk.Tk()
cols = ('name','age')
e = ttk.Treeview(root,columns=cols)
for col in cols:
            e.heading(col, text=col)
            e.column(col,minwidth=0,width=170)
e.pack()
e.insert("","end",values=("ss",66))
e.insert("","end",values=("yy",11))
root.mainloop()

您必须将回调函数绑定到相应的键盘事件。函数本身需要访问Treeview小部件。您可以通过在闭包中绑定
e
来实现这一点:

root.bind('<Control-a>', lambda *args: e.selection_add(e.get_children()))
root.bind(“”,lambda*args:e.selection\u add(e.get\u children())

很高兴它有帮助:)