title: How do I reference my Tkinter "root" instance from within another class?
body: <p>I am using the below code to create a window and raise different frames around. I need to create a toplevel, but I am trying to make the Toplevel window appear within the bounds of the main window. Looking around on here, I am finding the way to do this is to use wm_transient(root).  The problem is my &quot;root&quot; is called app, and its not accessible from within the class where I am calling these functions.</p>
  <p>So my popup function I am calling, I am trying to make my popup (toplevel) have the attribute of wm_transient, but I have to set the master to root (app in my application) and cannot figure out how to make this work.</p>
  <p>So my underlying question is how to make the toplevel appear within the bounds of my main window, but what I would really like to know is how to make calls/reference my root window.</p>
  <pre><code>import tkinter as tk
  
  class APP1(tk.Tk):
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)
          self.title('APP')
          self.geometry(&quot;552x700&quot;)
          self.resizable(False, False)
  
          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 = {}
  
          self.frames[&quot;MenuPage&quot;] = MenuPage(parent=container, controller=self)
          self.frames[&quot;MenuPage&quot;].grid(row=0, column=0, sticky=&quot;nsew&quot;)
          self.show_frame(&quot;MenuPage&quot;)
  
      def show_frame(self, page_name):
          frame = self.frames[page_name]
          frame.tkraise()
  
  class MenuPage(tk.Frame):
      def __init__(self, parent, controller):
          tk.Frame.__init__(self, parent)
          self.controller = controller
  
          def popup():
              x = tk.Toplevel(self)
              x.wm_transient(app)
  
          template = tk.Button(self, text='Popup', height=3, width=20, bg='white', font=('12'), command=lambda: popup())
          template.pack(pady=50)
  
  
  if __name__ == &quot;__main__&quot;:
      app = APP1()
      app.mainloop()
  </code></pre>