单击空白区域后清除选择

发布于 2025-01-20 14:05:41 字数 827 浏览 5 评论 0原文

我目前正在使用 python 3.9 并尝试在单击空白区域后清除选择
它看起来像这个

这是我的代码:

fileTreeView = ttk.Treeview(m, name='fileTreeView')
fileTreeView['columns']=('name', 'datem', 'type', 'size', 'blankspace')
fileTreeView.column('#0', width=0, stretch=NO)
fileTreeView.column('name',  width=60)
fileTreeView.column('datem',  width=60)
fileTreeView.column('type',  width=60)
fileTreeView.column('size',  width=60)
fileTreeView.column('blankspace', width=60)

fileTreeView.heading('#0')
fileTreeView.heading('name', text='Name')
fileTreeView.heading('datem', text='Date modified')
fileTreeView.heading('type', text='Type')
fileTreeView.heading('size', text='Size')
fileTreeView.heading('blankspace', text="")

我希望当单击空白列时,它将清除选择。

提前致谢!

I'm currently using python 3.9 and trying to clear the selection after clicking to a blank space
It looks something like this.

This is my code:

fileTreeView = ttk.Treeview(m, name='fileTreeView')
fileTreeView['columns']=('name', 'datem', 'type', 'size', 'blankspace')
fileTreeView.column('#0', width=0, stretch=NO)
fileTreeView.column('name',  width=60)
fileTreeView.column('datem',  width=60)
fileTreeView.column('type',  width=60)
fileTreeView.column('size',  width=60)
fileTreeView.column('blankspace', width=60)

fileTreeView.heading('#0')
fileTreeView.heading('name', text='Name')
fileTreeView.heading('datem', text='Date modified')
fileTreeView.heading('type', text='Type')
fileTreeView.heading('size', text='Size')
fileTreeView.heading('blankspace', text="")

I want when the blankspace column is clicked, it will clear the selection.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新一帅帅 2025-01-27 14:05:41

您可以在< button-1>事件的回调中找到单击的列,如果是blankSpace,则清除选择:

def on_clicked(event):
    # get the column index being clicked
    col = fileTreeView.identify_column(event.x)
    # get the column name of the clicked column
    name = fileTreeView.column(col, 'id')
    if name == 'blankspace':
        # clear the selection
        fileTreeView.selection_set()
        # disable default mouse click handler
        return 'break'

fileTreeView.bind('<Button-1>', on_clicked)

You can find the column being clicked inside the callback of <Button-1> event, if it is blankspace then clear the selection:

def on_clicked(event):
    # get the column index being clicked
    col = fileTreeView.identify_column(event.x)
    # get the column name of the clicked column
    name = fileTreeView.column(col, 'id')
    if name == 'blankspace':
        # clear the selection
        fileTreeView.selection_set()
        # disable default mouse click handler
        return 'break'

fileTreeView.bind('<Button-1>', on_clicked)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文