title: How to create an array to hold the values of several automatically generated checkboxes in Tk Tcl
body: <p>I have a list of objects of unknown length, I want to create 2 lists of checkboxes, in each list a checkbox for each line of the list. I also need to be able to get to the checkboxes and check their value.</p>
  
  <p>Since I didn't find a way to get the value of a checkbox from its path, I wanted to create a global array that will hold the variables for the check boxes, and tried the fallowing:</p>
  
  <pre><code>    global cb
      set i 0
      foreach port $ports {
      set to_cb    [checkbutton $to.cb_to_$i     -variable [list $cb(to$i)]   -text $port -command [list __sp_from_to_changed $from $to]]
      set from_cb  [checkbutton $from.cb_from_$i -variable [list $cb(from$i)] -text $port -command [list __sp_from_to_changed $from $to]]
  
      grid $to_cb   -row [expr $i + 2] -sticky nsew
      grid $from_cb -row [expr $i + 2] -sticky nsew
      incr i
  </code></pre>
  
  <p>When I source it  get the error <code>can't read "cb(to0)": no such variable</code>, how can I assign a variable inside an array for a check box, or better yet, is there a way to get the current value directly from the checkbox without using intermediate variables?</p>