title: Tkinter Make PageOne from Mr Bryan Oakley child of Mr. Mikhails' ScrolledWindow
body: <p>I´m using this very known script from Mr. Bryan Oakley. My question is: How make class PageOne child of ScrolledWindow  from Mr. Mikhail (<a href="https://stackoverflow.com/users/6470235/mikhail-tin">https://stackoverflow.com/users/6470235/mikhail-tin</a>). His script is in the question: <a href="https://stackoverflow.com/questions/16188420/tkinter-scrollbar-for-frame/69564648?noredirect=1#comment122962197_69564648">Tkinter scrollbar for frame</a>. But I wrote both bellow.</p>
  <p>When I try
  PageOne = ScrolledWindow(parent=SampleApp) python asks for controller, if I use container, it doesnot recognize it.
  If I use PageOne = ScrolledWindow(parent=SampleApp, controller = SampleApp.container)
  it says:
  SampleApp has no attribute 'container'</p>
  <p>I´m very curious about the answer of this puzzle.</p>
  <p>Thanks in advance.</p>
  <pre><code>import tkinter as tk                # python 3
  from tkinter import font as tkfont  # python 3
  from tkinter import ttk
  
  class SampleApp(tk.Tk):
  
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
  
          self.title_font = tkfont.Font(family='Helvetica', size=18, weight=&quot;bold&quot;, slant=&quot;italic&quot;)
  
          # the container is where we'll stack a bunch of frames
          # on top of each other, then the one we want visible
          # will be raised above the others
          container = tk.Frame(self)
          container.pack(side=&quot;top&quot;, fill=&quot;both&quot;, expand=True)
          container.grid_rowconfigure(0, weight=1)
          container.grid_columnconfigure(0, weight=1)
  
          self.frames = {}
          for F in (StartPage, PageOne, ScrolledWindow):
              page_name = F.__name__
              frame = F(parent=container, controller=self)
              self.frames[page_name] = frame
  
              # put all of the pages in the same location;
              # the one on the top of the stacking order
              # will be the one that is visible.
              frame.grid(row=0, column=0, sticky=&quot;nsew&quot;)
  
          self.show_frame(&quot;StartPage&quot;)
  
      def show_frame(self, page_name):
          '''Show a frame for the given page name'''
          frame = self.frames[page_name]
          frame.tkraise()
  
  
  class StartPage(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label = tk.Label(self, text=&quot;This is the start page&quot;, font=controller.title_font)
          label.pack(side=&quot;top&quot;, fill=&quot;x&quot;, pady=10)
  
          button1 = tk.Button(self, text=&quot;Go to Page One&quot;,
                              command=lambda: controller.show_frame(&quot;PageOne&quot;))
          button2 = tk.Button(self, text=&quot;ScrolledWindow&quot;,
                      command=lambda: controller.show_frame(&quot;ScrolledWindow&quot;))
          button1.pack()
          button2.pack()
  
          
  class PageOne(tk.Frame):
  
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label = tk.Label(self, text=&quot;This is page 1&quot;, font=controller.title_font)
          label.pack(side=&quot;top&quot;, fill=&quot;x&quot;, pady=10)
          button = tk.Button(self, text=&quot;Go to the start page&quot;,
                              command=lambda: controller.show_frame(&quot;StartPage&quot;))
  
          button.pack()
  
  class ScrolledWindow(tk.Frame):
      &quot;&quot;&quot;
      1. Master widget gets scrollbars and a canvas. Scrollbars are connected 
      to canvas scrollregion.
  
      2. self.scrollwindow is created and inserted into canvas
  
      Usage Guideline:
      Assign any widgets as children of &lt;ScrolledWindow instance&gt;.scrollwindow
      to get them inserted into canvas
  
      __init__(self, parent, canv_w = 400, canv_h = 400, *args, **kwargs)
      docstring:
      Parent = master of scrolled window
      canv_w - width of canvas
      canv_h - height of canvas
  
      &quot;&quot;&quot;
  
  
      def __init__(self, parent, controller, canv_w = 400, canv_h = 400, *args, **kwargs):
          &quot;&quot;&quot;Parent = master of scrolled window
          canv_w - width of canvas
          canv_h - height of canvas
  
          &quot;&quot;&quot;
          super().__init__(parent, *args, **kwargs)
  
          self.parent = parent
          
          button = tk.Button(self, text=&quot;Go to the start page&quot;,
                              command=lambda: controller.show_frame(&quot;StartPage&quot;))
  
          button.pack()
          
          # creating a scrollbars
          self.xscrlbr = ttk.Scrollbar(self.parent, orient = 'horizontal')
          self.xscrlbr.grid(column = 0, row = 1, sticky = 'ew', columnspan = 2)         
          self.yscrlbr = ttk.Scrollbar(self.parent)
          self.yscrlbr.grid(column = 1, row = 0, sticky = 'ns')         
          # creating a canvas
          self.canv = tk.Canvas(self.parent)
          self.canv.config(relief = 'flat',
                              width = 10,
                              heigh = 10, bd = 2)
          # placing a canvas into frame
          self.canv.grid(column = 0, row = 0, sticky = 'nsew')
          # accociating scrollbar comands to canvas scroling
          self.xscrlbr.config(command = self.canv.xview)
          self.yscrlbr.config(command = self.canv.yview)
  
          # creating a frame to inserto to canvas
          self.scrollwindow = ttk.Frame(self.parent)
  
          self.canv.create_window(0, 0, window = self.scrollwindow, anchor = 'nw')
  
          self.canv.config(xscrollcommand = self.xscrlbr.set,
                              yscrollcommand = self.yscrlbr.set,
                              scrollregion = (0, 0, 100, 100))
  
          self.yscrlbr.lift(self.scrollwindow)        
          self.xscrlbr.lift(self.scrollwindow)
          self.scrollwindow.bind('&lt;Configure&gt;', self._configure_window)  
          self.scrollwindow.bind('&lt;Enter&gt;', self._bound_to_mousewheel)
          self.scrollwindow.bind('&lt;Leave&gt;', self._unbound_to_mousewheel)
  
          return
  
      def _bound_to_mousewheel(self, event):
          self.canv.bind_all(&quot;&lt;MouseWheel&gt;&quot;, self._on_mousewheel)   
  
      def _unbound_to_mousewheel(self, event):
          self.canv.unbind_all(&quot;&lt;MouseWheel&gt;&quot;) 
  
      def _on_mousewheel(self, event):
          self.canv.yview_scroll(int(-1*(event.delta/120)), &quot;units&quot;)  
  
      def _configure_window(self, event):
          # update the scrollbars to match the size of the inner frame
          size = (self.scrollwindow.winfo_reqwidth(), self.scrollwindow.winfo_reqheight())
          self.canv.config(scrollregion='0 0 %s %s' % size)
          if self.scrollwindow.winfo_reqwidth() != self.canv.winfo_width():
              # update the canvas's width to fit the inner frame
              self.canv.config(width = self.scrollwindow.winfo_reqwidth())
          if self.scrollwindow.winfo_reqheight() != self.canv.winfo_height():
              # update the canvas's width to fit the inner frame
              self.canv.config(height= self.scrollwindow.winfo_reqheight())
              
  
  if __name__ == &quot;__main__&quot;:
      app = SampleApp()
      app.mainloop()
  </code></pre>