title: Switching frames with tkinter
body: <p>I've got the following application which consists of a menu bar and a frame. On a button press the content of the frame should be changed.</p>
  <p>Here's my code so far:</p>
  <pre><code>import tkinter as tk
  
  
  class ImageTool(tk.Tk):
  
      def __init__(self, *args, **kwargs):
          
          tk.Tk.__init__(self, *args, **kwargs)
  
          container = tk.Frame(self)
          container.grid(row=0,column=0,sticky=&quot;nsew&quot;)
          container.grid_rowconfigure(1, weight=1)
          container.grid_columnconfigure(2, weight=1)
  
          menu = SideMenu(container,self)
          menu.grid(row=0,column=0, sticky=&quot;nsew&quot;)
  
  
          self.frames = {}
  
          frame = StartPage(container, self)
          backuppage = BackupPage(container,self)
  
  
          self.frames[StartPage] = frame
          self.frames[BackupPage] = backuppage
  
          frame.grid(row=0, column=1, sticky=&quot;nsew&quot;)
  
  
          self.show_frame(StartPage)
  
      def show_frame(self, cont):
          print(self)
          frame = self.frames[cont]
          frame.tkraise()
  
          
  class StartPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self,parent)
          startpage_lbl = tk.Label(self, text=&quot;Start Page&quot;)
          startpage_lbl.pack(pady=10,padx=10,fill=&quot;both&quot;)
          
          self.winfo_toplevel().title(&quot;Image&quot;)
  
  class BackupPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self,parent)
          self.winfo_toplevel().title(&quot; Backup&quot;)
          
  class SideMenu(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self,parent)
          self.btn_backup = tk.Button(self,text=&quot;BACKUP&quot;, command= controller.show_frame(BackupPage))
          self.btn_restore = tk.Button(self,text=&quot;RESTORE&quot;)
  
          self.btn_backup.pack(side = tk.TOP, fill= tk.X, expand = True )
          self.btn_restore.pack(side = tk.TOP, fill= tk.X, expand = True )
  
  
  app = ImageTool()
  app.mainloop()
  </code></pre>
  <p>My problem is as follows:
  When I try to run the code above, I get an error that</p>
  <p><code>AttributeError: '_tkinter.tkapp' object has no attribute 'frames'</code></p>
  <p>However, if I'm not entirely mistaken, I pass the instance of ImageTool to the class SideMenu as controller which is why the command call to controller.show_frame(BackupPage) should work in theory.</p>
  <p>What is my mistake?</p>
  <p>Thank you very much in advance for any help.</p>