title: Python Tkinter Scrollbar within a Class
body: <p>My goal is to create a GUI TKinter class with vertical and horizontal scrolls.</p>
  
  <p>I have a chart whose dimension is bigger than the window dimension of the GUI. I put the chart within a canvas to enable the scrollbar function that allows vertical and horizontal scroll.</p>
  
  <p>However when I run my code, the graph size fits automatically to the size of the GUI window thus distorting the graph ratio and the scrollbar function is not working.</p>
  
  <p>Does anyone know the solution to this? Here is the code:</p>
  
  <pre><code>from tkinter import * 
  
  from numpy import arange, sin, pi
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  
  from matplotlib.figure import Figure
  
  
  class App(Tk):
      def __init__(self):
          Tk.__init__(self)
          Frame_parent = Frame(self, bg = 'white', borderwidth = 0, relief = FLAT)
          Frame_parent.pack(side = TOP, padx = 1, pady = 1)
  
          Canvas_parent = Canvas(Frame_parent, scrollregion = (0, 0, 2000, 2000))
          vbar=Scrollbar(Frame_parent, orient = VERTICAL)
          vbar.pack(side = RIGHT, fill = Y)
          vbar.config(command = Canvas_parent.yview)
          hbar=Scrollbar(Frame_parent, orient=HORIZONTAL)
          hbar.pack(side=BOTTOM,fill=X)
          hbar.config(command=Canvas_parent.xview)
  
          Canvas_parent.config(xscrollcommand=hbar.set, yscrollcommand = vbar.set)
          Canvas_parent.pack(side = LEFT, expand = True, fill = BOTH)
  
          Frame_child = Frame(Canvas_parent, bg = 'white', borderwidth = 2, relief = FLAT)
          Frame_child.pack(side = TOP, padx = 10, pady = 1)
  
  
          f = Figure(figsize=(6, 5), dpi=100)
          a = f.add_subplot(111)
          t = arange(0.0, 3.0, 0.01)
          s = sin(2*pi*t)
          a.plot(t, s)
  
  
          canvas = FigureCanvasTkAgg(f, Frame_child)
          canvas.show()
          canvas.get_tk_widget().pack(side = BOTTOM,  fill = BOTH,  expand = False)
  
  if __name__ == "__main__":
      app = App()
      app.geometry("400x400+51+51")
      app.title("Test")
      app.mainloop()
  </code></pre>