python - TkInter, slider : how to trigger the event only when the iteraction is complete?

标签 python tkinter

我正在使用 slider 来更新我的可视化效果,但每次我移动 slider 拇指时都会发送命令 updateValue,即使是中间值也是如此。

相反,我只想在松开鼠标按钮且交互完成时触发它。

self.slider = tk.Scale(self.leftFrame, from_=0, to=256, orient=tk.HORIZONTAL, command=updateValue)

如何在交互结束时只触发一次函数?

最佳答案

现在这是一个相当古老的问题,但万一有人偶然发现这个特定问题,只需使用 bind() 函数和“ButtonRelease-1”事件,如下所示:

import Tkinter as tk

class App:
    def __init__(self):
        self.root = tk.Tk()

        self.slider = tk.Scale(self.root, from_=0, to=256, 
                               orient="horizontal")
        self.slider.bind("<ButtonRelease-1>", self.updateValue)
        self.slider.pack()
        self.root.mainloop()

    def updateValue(self, event):
        print self.slider.get()

app=App()

希望这对任何人都有帮助!

关于python - TkInter, slider : how to trigger the event only when the iteraction is complete?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3966303/

相关文章:

python - 键绑定(bind) 1-5 不工作 Tkinter

python - 使用 SHAP 的 Tkinter 回调中的异常

python - 寻路算法无法正常工作

Python UDP recvfrom()具体地址

python - 为什么不能将 *args 从覆盖 int 的类传递给 super().__init__()?

python - 如何让窗口中的滚动条起作用?

python-3.x - 为什么 Canvas 滚动条在 tkinter 窗口中被禁用?

python - 删除内容后如何设置 tkinter 条目验证

python - 从自上而下的相机确定多边形表面旋转的方法

python - 如何在字典理解中使用 if/else?