title: Using a variable created within a class method in another class
body: <p>Using OOP based tkinter, I wish to use a variable created within a class method in another class, i.e. not the one in which it was created.</p>
  
  <p>The variable that I wish to use is 'MainGameWindow', the identifier for the instance of the class I am dealing with. It is initially created inside the class 'LoginWindow' in the method 'LoginUser', shown below:</p>
  
  <pre><code>def LoginUser(self):
      self.username=self.entry_username.get()
      self.usertg=self.entry_tutorg.get()
      self.logdetails=str(self.username)+' '+str(self.usertg)+'.txt'
      if os.path.isfile(self.logdetails)==True:
          #opening of main window
          self.master.destroy()
          root=Tk()
          MainGameWindow=MainGameClass(root)
  </code></pre>
  
  <p>I wish to then use this variable in another class, 'OptionsClass', in order to execute a class method in the 'MainGameClass' (the 'MainGameWindow' instance) using a command:</p>
  
  <pre><code>  self.radio_targetapp1=Radiobutton(self.master,text="Standard Mole",variable=self.app_var,value="placeholder1.gif",command=lambda:MainGameWindow.changeApp("placeholder1.gif"))
  </code></pre>
  
  <p>This is the method which I am attempting to execute:</p>
  
  <pre><code>    def changeApp(self,changeto):
         self.target_photo=PhotoImage(file=changeto)
         self.coords=self.canvas.coords(self.mole_target)
         self.theimg=self.canvas.create_image(self.coords[0],self.coords[1],image=self.target_photo)
  </code></pre>
  
  <p>In its current state I get the error 'NameError: global name 'MainGameWindow' is not defined'. I assume this is because the variable was created inside a class function and is therefore a local variable - how do I therefore use this variable outside of this function?</p>
  
  <p>Apologies if this question is long-winded, however I have searched for an answer and have not been able to find one.</p>
  
  <p>Many thanks in advance.</p>