title: Python, Tkinter: Get Text from Checkbutton when Checked
body: <p>I'm working with the following code.  My goal is to get the text of a Checkbutton when it is checked, and append that text to a list.  I want to write the code dynamically, because the size of list 'x' may change.  Here's what I have so far:</p>
  
  <pre><code>from Tkinter import *
  root = Tk()
  
  global j
  j = []
  
  x = ['hello', 'this', 'is', 'a', 'list']
  
  def chkbox_checked():
      j.append(c.cget("text"))
  
  for i in x:
  
      c = Checkbutton(root, text=i, command=chkbox_checked)
      c.grid(sticky=W)
  
  mainloop()
  
  print j
  </code></pre>
  
  <p>My output so far for j has been:</p>
  
  <pre><code>['list', 'list', 'list', 'list', 'list'] #depending on how many Checkbuttons I select
  </code></pre>
  
  <p>I'm looking for an output that is like this:</p>
  
  <pre><code>['this', 'list'] #depending on the Checkbuttons that I select; this would be the output if I
  #selected Checkbuttons "this" and "list".
  </code></pre>
  
  <p>I've experimented with the "variable" option in the Checkbutton, but I can't seem to connect the dots.  Can anyone point me in the right direction?  I have a feeling it's relatively straightforward.  Thanks!</p>