在TCL/TK中,在小部件销毁后移除绑定。

huangapple go评论63阅读模式
英文:

In TCL/TK Remove binding after widget destruction

问题

I have a canvas located in a Sub window of my main application:

在我的主应用程序的子窗口中有一个画布:

.dsm.nb.mdlbuild.canvas

additionally I have the following (one of several) proc helping me letting the user move stuff around on the canvas:

此外,我还有以下(多个之一)过程,帮助用户在画布上移动物体:

proc grab { xx yy } {

过程抓取 { xx yy } {

global currentx currenty
set currentx $xx
set currenty $yy
}

I use this binding:

我使用这个绑定:

.dsm.nb.mdlbuild.canvas bind $tagtomove {grab %x %y }

PROBLEM:

问题:

When the user closes the window (.dsm) the canvas gets distroyed to, but the binding seems to 'survive'.

当用户关闭窗口(.dsm)时,画布也被销毁了,但绑定似乎“幸存”。

When the user then subsequentually clicks somwhere he gets the error:

然后,当用户随后点击某处时,他会收到错误消息:

wrong args: should be "grab xx yy"

参数错误:应该是“grab xx yy”

This because xx and yy is empty i suppose because the canvas is gone together with the parrent window...

这是因为 xx 和 yy 是空的,我想是因为画布和父窗口一起消失了…

I have tried to set the binding to nothing after the .dsm window is destroyed:

我尝试在销毁.dsm窗口后将绑定设置为空:

.dsm.nb.mdlbuild.canvas bind $tagtomove { }

and to use the "break" command, but with no success.

并尝试使用“break”命令,但没有成功。

.dsm.nb.mdlbuild.canvas bind $tagtomove break

How can i remove the binding uppon closing the window (.dsm) in which the canvas is located so that this error does dissapear?

如何在关闭包含画布的窗口(.dsm)时删除绑定,以使此错误消失?

英文:

I have a canvas located in a Sub window of my main application:

.dsm.nb.mdlbuild.canvas

additionally I have the following (one of several) proc helping me letting the user move stuff around on the canvas:

proc grab { xx yy } {

    global currentx currenty
    set currentx $xx
    set currenty $yy
}

I use this binding:

.dsm.nb.mdlbuild.canvas bind $tagtomove  <Button-1>      {grab  %x %y }

PROBLEM:

When the user closes the window (.dsm) the canvas gets distroyed to, but the binding seems to 'survive'.

When the user then subsequentually clicks somwhere he gets the error:

wrong args: should be "grab xx yy"

This because xx and yy is empty i suppose because the canvas is gone together with the parrent window...

I have tried to set the binding to nothing after the .dsm window is destroyed:

.dsm.nb.mdlbuild.canvas bind $tagtomove  <Button-1>      { }

and to use the "break" command, but with no success.

.dsm.nb.mdlbuild.canvas bind $tagtomove  <Button-1>      break

How can i remove the binding uppon closing the window (.dsm) in which the canvas is located so that this error does dissapear?

答案1

得分: 3

问题很可能是您在定义过程时使用了标准 Tk 命令的名称。grab 命令在 Tk 库中的不同位置被调用,但不总是匹配您的过程的参数数量。这会导致错误。您可以在收到错误消息后通过转储$errorInfo的值来检查此问题。

因此,只需将您的过程重命名为与grab(或任何其他内置命令)不同的名称。

英文:

The problem is most likely that you used the name of a standard Tk command for your proc. The grab command is called from different places in the Tk library, but not always matching the number of arguments of your proc. This would cause the error. You can check this by dumping the value of $errorInfo after you received the error message.

So, just rename your proc to something other than grab (or any other built-in command).

huangapple
  • 本文由 发表于 2020年1月6日 23:03:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定