title: Creating a variable to store entry box information for other frames using tkinter
body: <p>This is my first time posting a question so I'm sorry in advanced if I do anything wrong when posting the question. <br/> <br/>I am using tkinter and using the same code as an answer that was posted here that used classes to create and show frames:<br/> <a href="https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter/7557028#7557028">Switch between two frames in tkinter</a> <br/><br/>  I want to be able to create global variables so that other frames can use them when needed. I tried using <code>root = tk.Tk()</code> and creating the global variable that way, but noticed that when doing that, not only did I not get the entry from the entry box, but it created a new window. I also tried <code>global_var = tk.StringVar()</code>, not having <code>root = tk.Tk()</code>, but got an error stating: <br/></p>
  <blockquote>
  <p>Traceback (most recent call last):   File &quot;app.py&quot;, line 6, in
  
  name_var = tk.StringVar()   File &quot;/usr/lib/python3.7/tkinter/<strong>init</strong>.py&quot;, line 480, in <strong>init</strong>
  Variable.<strong>init</strong>(self, master, value, name)   File &quot;/usr/lib/python3.7/tkinter/<strong>init</strong>.py&quot;, line 317, in <strong>init</strong>
  self._root = master._root() AttributeError: 'NoneType' object has no attribute '_root'</p>
  </blockquote>
  <p>Is there a way for me to store that input from the entry box, and use it in another frame?</p>
  <p>Source Code</p>
  <pre><code>class SampleApp(tk.Tk):
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
          self.title_font = tkfont.Font(family = 'Garamond', size = 18, weight = &quot;bold&quot;, slant = &quot;italic&quot;)
  
      #container we'll stack frames on top of each other, then the one we want to
          #visible will be raised above the others
          container = tk.Frame(self)
          container.pack(side = &quot;top&quot;, fill = &quot;both&quot;, expand = &quot;True&quot;)
          container.grid_rowconfigure(0, weight = 1)
          container.grid_columnconfigure(0, weight = 1)
  
          self.frames = {}
          for F in (StartPage, PageOne, PageTwo, UserInfo):
              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()
          frame.configure(background = 'teal')  
  
  class StartPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          self.controller.geometry(&quot;800x400&quot;)
  
          label = tk.Label(self, text = &quot;Facial Recognition Lock&quot;, font = controller.title_font)
          label.pack(side = &quot;top&quot;)
  
          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;Go to Page Two&quot;, command = lambda: controller.show_frame(&quot;PageTwo&quot;))
  
          Exitbutton = tk.Button(self, text=&quot;Exit&quot;, width = 8, height = 3, command = self.Exit)
  
          button1.place(x = 200, y = 200)
          button2.place(x = 600, y = 200)
          Exitbutton.place(x = 350, y = 330)
  
      def Exit(self):
          self.controller.destroy()   
  
  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 One&quot;, font = controller.title_font)
          label.pack(side = &quot;top&quot;)
  
          button1 = tk.Button(self, text = &quot;Go to Start Page&quot;,
                          command = lambda: controller.show_frame(&quot;StartPage&quot;))
  
          button2 = tk.Button(self, text = &quot;Go to Page Two&quot;,
                          command = lambda: controller.show_frame(&quot;PageTwo&quot;))
  
          button3 = tk.Button(self, text = &quot;User Info&quot;,
                          command = lambda: controller.show_frame(&quot;UserInfo&quot;))
  
          button1.place(x = 200, y = 200)
          button2.place(x=400, y = 200)
          button3.place(x=300, y =340)     
  
  class UserInfo(tk.Frame):    
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
          label1 = tk.Label(self, text = &quot;User Info&quot;, font = controller.title_font)  
          label1.pack(side = &quot;top&quot;)
  
          label2 = tk.Label(self, text = &quot;User's Name&quot;, font = &quot;Arial 13&quot;)
          label2.place(x=100, y=100)
  
          button1 = tk.Button(self, text = &quot;Go to Start Page&quot;,
                          command = lambda: controller.show_frame(&quot;StartPage&quot;))
  
          button1.place(x=300, y = 350)
  
          nameEntry = tk.Entry(self, textvariable = name_var, bd = 5, font=('calibre',10,'normal'))
          nameEntry.place(x=220, y=100)
  
          showButton = tk.Button(self, text=&quot;Show&quot;, command = submit)
  
          showButton.place(x=200, y = 250)
  
  if __name__ == &quot;__main__&quot;:
      app = SampleApp()
      app.mainloop()  
  </code></pre>
  <p><em>Excluded PageTwo Class as it's similar to PageOne</em></p>