Tcl/Tk-无法将类方法附加为按钮命令
我试图将一个方法附加到一个命令按钮上,但收到以下错误消息。如果我附加一个proc,它工作正常 如何做到这一点Tcl/Tk-无法将类方法附加为按钮命令,tcl,tk,itcl,Tcl,Tk,Itcl,我试图将一个方法附加到一个命令按钮上,但收到以下错误消息。如果我附加一个proc,它工作正常 如何做到这一点 % itcl::class a { method test {} {puts test} constructor {} { button .t.b -command test; grid config .t.b -column 0 -row 0 } } % a A invalid command name "resize"
% itcl::class a {
method test {} {puts test}
constructor {} {
button .t.b -command test;
grid config .t.b -column 0 -row 0
}
}
% a A
invalid command name "resize"
invalid command name "resize"
while executing
"resize"
invoked from within
".t.b invoke"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list $w invoke]"
(procedure "tk::ButtonUp" line 24)
invoked from within
"tk::ButtonUp .t.b"
(command bound to event)
好吧,那么“这”就是关键
% itcl::class a {
method test {} {puts test}
constructor {} {
button .t.b -command "$this test";
grid config .t.b -column 0 -row 0
}
}
好吧,那么“这”就是关键
% itcl::class a {
method test {} {puts test}
constructor {} {
button .t.b -command "$this test";
grid config .t.b -column 0 -row 0
}
}
按钮回调是在全局上下文中处理的,因为按钮不知道itcl类,并且回调发生在类不在执行堆栈上的时候。这意味着回调需要使用允许外部代码调用方法的表单之一:
# The form with "$this test" is not preferred as it can go wrong with complex data.
# It tends to show up when you tidy things up for a demo! Using [list] avoids trouble.
button .t.b -command [list $this test]
按钮回调是在全局上下文中处理的,因为按钮不知道itcl类,并且回调发生在类不在执行堆栈上的时候。这意味着回调需要使用允许外部代码调用方法的表单之一:
# The form with "$this test" is not preferred as it can go wrong with complex data.
# It tends to show up when you tidy things up for a demo! Using [list] avoids trouble.
button .t.b -command [list $this test]
是
测试
还是调整大小
?纠正了相同的错误是测试
还是调整大小
?纠正了相同的错误