title: How to place widgets into different frames in Tkinter, using OOP
body: <p><strong>Background</strong></p>
  
  <p>Hello everyone! I am currently working on a basic GUI text editor which can load and save text files. I want to use multiple frames for the toolbar and the textbox as I learned <a href="https://stackoverflow.com/questions/14846063/what-is-a-better-tkinter-geometry-manager-than-grid">here.</a> I am using OOP, and have set up my frames in the <code>__init__</code> method, and the widgets in the <code>widget</code> method. For some reason, the widgets are unable to be placed within their respective Frames.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>from Tkinter import *
  class Application:
      def __init__(self,parent):  #initialize the grid and widgets
          self.myParent = parent
  
          #Init the toolbar
          self.toolbar = Frame(parent)
          self.toolbar.grid(row = 0)
  
          #Init frame for the text box
  
          self.mainframe = Frame(parent)
          self.toolbar.grid(row = 1)
      def widget(self):#Place widgets here
  
          #Save Button
          self.saveButton = Button (self, self.toolbar,
                                    text = "Save", command = self.saveMe)
          self.saveButton.grid(column = 0, row = 0, sticky = W)
  
          #Open Button
          self.openButton = Button (self, self.toolbar,
                                   text = "Open", command = self.openMe)
          self.openButton.grid(column = 0, row = 1, sticky = W)
          #Area where you write 
          self.text = Text (self, self.mainframe,
                            width = (root.winfo_screenwidth() - 20),
                            height = (root.winfo_screenheight() - 10))
         self.text.grid(row = 2)
  </code></pre>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li><p>Still using different methods, how can I make sure that each widget is placed in the correct Frame?</p>
  
  <ul>
  <li>If this is not possible, please just show me how to do it using OOP - I am most comfortable with Tkinter in that setting and have promised myself to improve.</li>
  </ul></li>
  <li><p>Please <em>explain</em> your answer. I <em>need</em> to cognate - not simply nod my head at the computer and go right along. </p></li>
  <li><p>Extra Credit: How would I initialize multiple windows (each window being a different class) using Tkinter in OOP? For instance, if this was my code:</p>
  
  <pre><code>class MainWindow(Frame):
      ---init stuff---
      def widget(self):
          newWindow = Button(self, text = "click for a new window",
                             command = self.window)
          newWindow.grid()
     def window(self):
           #What would I put in here to initialize the new window??
  
  class theNextWindow(Frame):
  </code></pre>
  
  <p>What would I put in the <code>window.self</code> method to make the <code>theNextWindow</code> window visible?</p></li>
  </ol>
  
  <p>Thanks for everyone's help! </p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>I added the line <code>self.widget()</code> in the <code>__init__</code> method, and I was rewarded with this "wonderful" error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "D:\Python Programs\Text Editor\MyTextv2.py", line 67, in &lt;module&gt;
   app = Application(root)
  File "D:\Python Programs\Text Editor\MyTextv2.py", line 14, in __init__
   self.widget()
  File "D:\Python Programs\Text Editor\MyTextv2.py", line 24, in widget
   text = "Save", command = self.saveMe)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 2044, in __init__
   Widget.__init__(self, master, 'button', cnf, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1965, in __init__
   BaseWidget._setup(self, master, cnf)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1943, in _setup
   self.tk = master.tk
  AttributeError: Application instance has no attribute 'tk'
  </code></pre>
  
  <p>As the error log clearly references my mainloop here: <code>File "D:\Python Programs\Text Editor\MyTextv2.py", line 67, in &lt;module&gt;
       app = Application(root)</code> I decided to add it:</p>
  
  <pre><code>root = Tk()
  root.title("My Text Editor")
  
  #This is wierd - it gets the computer windows dimensions
  w, h = root.winfo_screenwidth(), root.winfo_screenheight()
  root.overrideredirect(0)
  
  #And then applies them here
  root.geometry("%dx%d+0+0" % (w, h))
  
  app = Application(root)
  
  root.mainloop()
  </code></pre>