title: Extracting a list of items from tkinter.Listbox
body: <p>I wrote the following tkinter script to understand how to add a list of data into a tkinter.Listbox widget. I discovered 2 methods for doing so.</p>
  
  <p>Next, I wanted to extract the same list from the tkinter.Listbox widget. Out of the 4 different approaches, I only managed to get the 4th approach (i.e. e4) to work.</p>
  
  <p>How can I get approaches e1, e2 and e3 to work? The end goal is to get the same list that was initially supplied to the tkinter.Listbox widget.</p>
  
  <p><strong>Test Script:</strong></p>
  
  <pre><code>import tkinter as tk # Python 3 tkinter modules
  import tkinter.ttk as ttk
  
  class App(ttk.Frame):
      def __init__(self, parent, *args, **kwargs):
          # 1. Initialise Frame
          ttk.Frame.__init__(self, parent)
          self.parent = parent
  
          # Method1
          name1 = ['Peter', 'Scotty', 'Walter', 'Scott', 'Mary']
          self.lb1_values = tk.StringVar(value=name1)
          self.listbox1 = tk.Listbox(self, listvariable=self.lb1_values)
  
          # Method2
          self.listbox2 = tk.Listbox(self)
          name2 = ['Sarah', 'Sean', 'Mora', 'Mori', 'Mary']
          for item in name2:
              self.listbox2.insert(tk.END, item)
  
          self.listbox1.grid(in_=self, row=0, column=0, sticky='nsew')
          self.listbox2.grid(in_=self, row=0, column=1, sticky='nsew')
  
          # Extract values from listbox and covert to a list
          e1 = self.lb1_values.get()
          print('e1 = ', e1)
          print('type(e1) = ', type(e1))
          e1 = e1.strip(',')
          print('e1 = ', e1)
  
          e2 = self.listbox1.cget('listvariable')
          print('\ne2 = ', e2)
          print('type(e2) = ', type(e2))
          e2 = e2.split(',')
          print('e2 = ', e2)
  
          e3 = self.listbox2.cget('listvariable')
          print('\ne3 = ', e3)
          print('type(e3) = ', type(e3))
  
          e4 = self.listbox2.get(0, tk.END)
          print('\ne4 = ', e4)
          print('type(e4) = ', type(e4))
          e4 = list(e4)
          print('e4 = ', e4)    
  
  
  if __name__ == '__main__':
      root = tk.Tk()
      root.title('App'), root.geometry('400x200')
      app = App(root)
      app.grid(row=0, column=0, sticky='nsew')
      #root.mainloop()
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>e1 =  ('Peter', 'Scotty', 'Walter', 'Scott', 'Mary')
  type(e1) =  &lt;class 'str'&gt;
  e1 =  ('Peter', 'Scotty', 'Walter', 'Scott', 'Mary')
  
  e2 =  PY_VAR0
  type(e2) =  &lt;class 'str'&gt;
  e2 =  ['PY_VAR0']
  
  e3 =  
  type(e3) =  &lt;class 'str'&gt;
  
  e4 =  ('Sarah', 'Sean', 'Mora', 'Mori', 'Mary')
  type(e4) =  &lt;class 'tuple'&gt;
  e4 =  ['Sarah', 'Sean', 'Mora', 'Mori', 'Mary']
  </code></pre>