1

我在 TCL/Tk 应用程序中有以下内容:

 proc greyout { } {
     puts "current part $DSM::Part"
     switch $DSM::Part {
 Doghouse {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry  configure -state disabled
         .dsm.traceLATpart$entry  configure -state disabled
         .dsm.traceStowage$entry  configure -state disabled      
         .dsm.traceDoghouse$entry configure -state enabled}
        }
  Stowage {
     for {set entry 1} {$entry<17} {incr entry} { 
         .dsm.traceCTRpart$entry configure -state disabled
         .dsm.traceLATpart$entry configure -state disabled
         .dsm.traceStowage$entry configure -state enabled        
         .dsm.traceDoghouse$entry configure -state disabled}
        }   
     }   
 }

  trace add variable DSM::Part write greyout

每次“部分”更改跟踪尝试调用灰色但我收到以下消息:

 wrong # args: should be "greyout"
 wrong # args: should be "greyout"
 while executing
"greyout Part {} write"
(write trace on "Part")
invoked from within
"variable Part "CTR_Partition""
(in namespace eval "::DSM" script line 3)
invoked from within.....

我不明白为什么?!有什么帮助吗?

4

1 回答 1

2

问题是当跟踪回调被触发时,额外的参数被附加到回调中,用于提供有关触发回调的触发事件的信息。因为您的代码仅对单个变量进行跟踪,所以这些参数目前对您不是很有用,但它们在更复杂的情况下很有帮助。

调整代码以处理此问题的最简单方法是使用特殊的形式参数greyout获取任意数量的参数:args

proc greyout {args} {
    puts "current part $DSM::Part"
    ...
}
于 2013-05-08T13:34:29.603 回答