gpt4 book ai didi

python-3.x - 在 Python3/tkinter 中有没有办法暂时停止接受 Treeview 小部件中的点击?

转载 作者:行者123 更新时间:2023-12-05 07:48:48 26 4
gpt4 key购买 nike

我有一个基于 Python 3 和 tkinter 的 GUI,它有一个很大的 ttk.Treeview。我已经定义了行选择(单击)和打开高级信息面板(双击)的方法。我需要确保在双击之后,在接下来的一两秒内,Treeview 状态不会因再次单击而改变。是否可以停用 Treeview 鼠标绑定(bind),就像我们对按钮所做的一样?

最佳答案

经过更多研究,我找到了解决方案。我刚刚创建了一个空方法,当树小部件应该处于非事件状态时调用该方法。因此,我们可以使用类似这样的方法来“解除绑定(bind)”所有鼠标事件,并在几秒钟后根据需要重新绑定(bind)它们:

def nothing(self, *event):
""" # Hacking moment: A function that does nothing, for those times you need it...
"""
pass


def bind_tree(self):
""" # Bind mouse and keyboard events to their respective functions or methods...
"""
self.tree.bind('<<TreeviewSelect>>', self.selectItem_popup)
self.tree.bind('<Double-1>', self.show_details)
self.tree.bind("<Button-2>", self.popupMenu)
self.tree.bind("<Button-3>", self.popupMenu)

def unbind_tree(self):
""" # Unbind all mouse and keyboard events, by binding them to an empty method...
"""
self.tree.bind('<<TreeviewSelect>>', self.nothing)
self.tree.bind('<Double-1>', self.nothing)
self.tree.bind("<Button-2>", self.nothing)
self.tree.bind("<Button-3>", self.nothing)

然后,在剩下的代码中,我们只需要根据需要调用bind_tree()unbind_tree()即可。

关于python-3.x - 在 Python3/tkinter 中有没有办法暂时停止接受 Treeview 小部件中的点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38188426/

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