title: How to pass 'self' parameter of one class to another class
body: <p>I am trying to incorporate matplotlib into tkinter by having multiple frames. I need to pass the entry inputs from <code>StartPage</code> frame to update the plot in <code>GraphPage</code> once the button in <code>StartPage</code> is clicked. Therefore, I'm trying to bind the update function of <code>GraphPage</code> to the button in <code>StartPage</code>, but the update function requires <code>self</code> parameter which I can't get. Here's the set up of my code right now:</p>
  
  <pre><code>import matplotlib
  matplotlib.use("TkAgg")
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
  from matplotlib.figure import Figure
  
  import tkinter as tk
  from tkinter import ttk
  
  
  class PeakFitting(tk.Tk):
  
      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 (StartPage, GraphPage):
  
              frame = F(container, self)
  
              self.frames[F] = frame
  
              frame.grid(row=0, column=0, sticky="nsew")
  
          self.show_frame(StartPage)
  
      def show_frame(self, cont):
  
          frame = self.frames[cont]
  
          frame.tkraise()
  
      def get_page(self, classname):
      '''Returns an instance of a page given it's class name as a string'''
          for page in self.frames.values():
              if str(page.__class__.__name__) == classname:
                  return page
          return None
  
  class StartPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
  
          self.controller = controller
  
         # Setting up frame and widget
  
          self.entry1 = tk.Entry(self)
          self.entry1.grid(row=4, column=1)
  
          button3 = ttk.Button(self, text="Graph Page",
                           command=self.gpUpdate())
          button3.grid(row=7, columnspan=2)
  
      def gpUpdate(self):
          graphPage = self.controller.get_page("GraphPage")
          GraphPage.update(graphPage)
          self.controller.show_frame("GraphPage")
  
  class GraphPage(tk.Frame):
      def __init__(self, parent, controller):
  
          tk.Frame.__init__(self, parent)
          self.controller = controller
  
          fig = Figure(figsize=(5, 5), dpi=100)
          self.a = fig.add_subplot()
  
          canvas = FigureCanvasTkAgg(fig, self)
          canvas.show()
          canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
  
          toolbar = NavigationToolbar2TkAgg(canvas, self)
          toolbar.update()
          canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
  
          startpage = self.controller.get_page("StartPage")
  
  
      def update(self):
  
          startpage = self.controller.get_page("StartPage")
          self.iso = startpage.entry1.get()
  
  ##Calculation code for analysis not needed for question
  
  app = PeakFitting()
  app.mainloop()
  </code></pre>
  
  <p>for <code>gpUpdate</code> function in <code>StartPage</code>, I tried to pass <code>graphPage</code> as <code>self</code>, but got an Error that it's a <code>NoneType</code>. I also tried <code>GraphPage.update(GraphPage)</code> but get 'type object 'GraphPage' has no attribute 'controller'' Error. </p>
  
  <p>I'm very sorry if my explanation wasn't clear, but I am very new to Python and has been struggling for weeks now to pass the entries to GraphPage class after the button is clicked but still can't do it... Can anyone please help me with this problem?</p>
  
  <p>Thank you so much!!!</p>
  
  <p>EDIT: I guess my main problem is how to call a function of one class in another class, because I don't know what the <code>self</code> parameter should be :(</p>
  
  <p>EDIT2: Changes to code thanks to suggestion:</p>
  
  <pre><code>def gpUpdate(self):
      self.parent = PeakFitting()
      self.grpage = GraphPage(self.parent.container, self.parent)
      self.grpage.update()
      self.controller.show_frame(GraphPage)
  </code></pre>
  
  <p>However, when I input something in the entry and hit the button, the <code>self.iso</code> field still remains empty...</p>