在 tcl/tk 中按下和按下按钮时执行
Acting when button down and button up in tcl/tk
我想在 tcl/tk.
中检测按钮何时被按下(向下)但未被释放(向上)
当你点击一个按钮时,它的相关命令只有在你松开并且按钮恢复原状后才会执行。
From tcl/tk documentation:
"Command-Line Name: -command
Database Name: command
Database Class: Command
Specifies a Tcl command to associate with the button. This command is typically invoked when mouse button 1 is released over the button window."
通常?
按下按钮时我的命令如何执行?
-command
回调实际上是一个响应特定事件序列而触发的高级事件。在低级别事件方面,您必须 <Enter>
小部件,<ButtonPress-1>
(通常缩写为 <Button-1>
或只是 <1>
)在按钮上以开始点击,然后<ButtonRelease-1>
在按钮上,同时在中间期间没有执行 <Leave>
或 <B1-Leave>
(没有 <Enter>
或 <B1-Enter>
来反转它)。有点复杂!
但您始终可以添加自己的绑定。
bind .btn <ButtonPress-1> {puts "pressed the button"}
bind .btn <ButtonRelease-1> {puts "released the button"}
如果您正在做任何复杂的事情,请注意以 break
结束的绑定脚本将阻止任何后续绑定(例如,按钮 class 绑定)触发。按钮对这些事件有 class 绑定:<ButtonRelease-1>
、<Button-1>
、<Leave>
、<Enter>
、<<Invoke>>
(这是一个虚拟事件),以及<Key-space>
.
我想在 tcl/tk.
中检测按钮何时被按下(向下)但未被释放(向上)当你点击一个按钮时,它的相关命令只有在你松开并且按钮恢复原状后才会执行。
From tcl/tk documentation: "Command-Line Name: -command Database Name: command Database Class: Command Specifies a Tcl command to associate with the button. This command is typically invoked when mouse button 1 is released over the button window."
通常?
按下按钮时我的命令如何执行?
-command
回调实际上是一个响应特定事件序列而触发的高级事件。在低级别事件方面,您必须 <Enter>
小部件,<ButtonPress-1>
(通常缩写为 <Button-1>
或只是 <1>
)在按钮上以开始点击,然后<ButtonRelease-1>
在按钮上,同时在中间期间没有执行 <Leave>
或 <B1-Leave>
(没有 <Enter>
或 <B1-Enter>
来反转它)。有点复杂!
但您始终可以添加自己的绑定。
bind .btn <ButtonPress-1> {puts "pressed the button"}
bind .btn <ButtonRelease-1> {puts "released the button"}
如果您正在做任何复杂的事情,请注意以 break
结束的绑定脚本将阻止任何后续绑定(例如,按钮 class 绑定)触发。按钮对这些事件有 class 绑定:<ButtonRelease-1>
、<Button-1>
、<Leave>
、<Enter>
、<<Invoke>>
(这是一个虚拟事件),以及<Key-space>
.