gpt4 book ai didi

python - TreeView 小部件中的 CTRL + a - Python

转载 作者:行者123 更新时间:2023-12-04 09:16:56 25 4
gpt4 key购买 nike

请帮助我使用 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()

最佳答案

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

root.bind('<Control-a>', lambda *args: e.selection_add(e.get_children()))

关于python - TreeView 小部件中的 CTRL + a - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com