单击空白后清除选择 space
Clear the selection after clicking a blank space
我目前正在使用 python 3.9 并尝试在单击空白后清除选择 space
它看起来像 this.
这是我的代码:
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="")
我希望当单击空白space 列时,它会清除选择。
提前致谢!
你可以在<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)
我目前正在使用 python 3.9 并尝试在单击空白后清除选择 space
它看起来像 this.
这是我的代码:
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="")
我希望当单击空白space 列时,它会清除选择。
提前致谢!
你可以在<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)