سؤال

I want to make several objects, all with the same parameters, so I tried to store them in a proc that returns them. But the interpreter evaluates the returning result as one parameter, instead of several. my proc is:

proc element_param {} {
    return "-filled 1\
        -visible 1\
        -linewidth 1\
        -linecolor yellow\
        -fillcolor yellow\
        -relief roundraised\
        -linewidth 2"
}

and I use it with:

$this/zinc add rectangle 1 [list "100" "100" "200" "200"] [element_param]

How do I turn them into several different parameters?

هل كانت مفيدة؟

المحلول

With tcl 8.5 and above use the {*} operator to expand the list of parameters:

$this/zinc add rectangle 1 $coords {*}[element_param]

with previous versions you can expand lists using eval:

eval [linsert [element_param] 0 $this/zinc add rectangle 1 $coords]

which is equivalent.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top