title: Accessing variable from another function in a function while using class() method
body: <p>I'm wondering if there is any ways to access variable through different functions?  Below is my code, Inside isWinner(), I want to access text of my buttons. How could it be done?<a href="https://i.stack.imgur.com/e9TIz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e9TIz.png" alt="enter image description here" /></a></p>
  <pre><code>class ttt():
      master = 0
      player1 = 0
      player2 = 0
      bclick = True
      buttonCounter = 1
      win = 0
      lose = 0
  
      def boardDisplay(self):
          button1 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button1), height=4, width=10)
          button1.place(x=275, y=150)
          button2 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button2), height=4, width=10)
          button2.place(x=355, y=150)
          button3 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button3), height=4, width=10)
          button3.place(x=435, y=150)
          button4 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button4), height=4, width=10)
          button4.place(x=275, y=230)
          button5 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button5), height=4, width=10)
          button5.place(x=355, y=230)
          button6 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button6), height=4, width=10)
          button6.place(x=435, y=230)
          button7 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button7), height=4, width=10)
          button7.place(x=275, y=310)
          button8 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button8), height=4, width=10)
          button8.place(x=355, y=310)
          button9 = tk.Button(self.master, text=&quot; &quot;, command=lambda: self.buttonClick(button9), height=4, width=10)
          button9.place(x=435, y=310)
  
      def buttonClick(self, button):
          if button[&quot;text&quot;] == &quot; &quot; and self.bclick == True:
              button[&quot;text&quot;] = &quot;X&quot;
              self.bclick = False
              self.isWinner()
              self.buttonCounter += 1
          elif button[&quot;text&quot;] == &quot; &quot; and self.bclick == False:
              button[&quot;text&quot;] = &quot;O&quot;
              self.bclick = True
              self.isWinner()
              self.buttonCounter += 1
          else:
              tk.messagebox.showinfo(&quot;Tic Tac Toe&quot;, &quot;Button is clicked already!&quot;)
  
      def isWinner(self): 
  </code></pre>