title: Pass arrays between Python classes
body: <p>I have data in <code>x</code> and <code>y</code> arrays that I want to pass between two Python classes.  When <code>button</code> is clicked I run <code>command=lambda: controller.show_frame(PlotPage)</code> to switch from <code>SelectPage</code> (which chooses data) to <code>PlotPage</code> (which plots x and y).  I want <code>x</code> and <code>y</code> saved before the page switch or within the <code>button</code> lambda.  Is saving the arrays as global variables the best way to pass the data to <code>PlotPage</code>, or is there a more convenient way to include these arrays in the button lambda function?</p>
  
  <pre><code># possible global variables
  global x = [stuff x]
  global y = [stuff y]    
  
  class SelectPage(tk.Frame):
      def __init__(self,parent,controller):
          button = tk.Button(self,text="Plot",
              command=lambda: controller.show_frame(PlotPage),
              [some_lambda_here])    # Possible lambda addition
  
  class PlotPage(tk.Frame):
      def __init__(self,parent,controller):
          [Tkinter plot intialization stuff]
          plotData(x,y)  # plotData creates the plot
  </code></pre>
  
  <p>Controller Class:</p>
  
  <pre><code>class Project:
  
  def __init__(self, *args,**kwargs):
      tk.Tk.__init__(self,*args,**kwargs)
      container = tk.Frame(self)
  
      container.pack(side="top",fill="both",expand=True)
  
      container.grid_rowconfigure(0,weight=1)
      container.grid_columnconfigure(0,weight=1)
  
      self.frames = {}
  
      for F in (SelectPage, PlotPage):
  
          frame = F(container, self)
  
          self.frames[F] = frame
  
          frame.grid(row=0,column = 0, sticky = "nsew")
  
      self.show_frame(StartPage)
  
  def show_frame(self, container):
  
      frame = self.frames[container]
      frame.tkraise()
  </code></pre>