title: Snakes and Ladders using tkinter python
body: <pre><code>import random
  from tkinter import *
  
  class Spinner(object):
  
  @staticmethod
  def getSpin():
      newSpin = random.randint(1,6)
      return newSpin
  
  class Player(object):
  
  def __init__(self,name):
      self.position = 1
      self.name = name
  
  def setName(self,name):
      self.name = name
  
  def changePosition(self,number):
      self.position = self.position + number
  
  def setPosition(self,pos):
      self.position = pos
      return self.position
  
  def getPosition(self):
      return self.position
  
  def getName(self):
      return self.name
  
  def spin(self):
      newSpin = Spinner.getSpin()
      self.position = self.position + newSpin
      print(str(self.name) + "'s spin was: " + str(newSpin))
  
  class Path(object):
        @staticmethod    
        def buildLadders():
      ladders = [[0 for x in range(2)] for x in range(9)]
      ladders[0][0] = 2
      ladders[0][1] = 9
      ladders[1][0] = 8
      ladders[1][1] = 11
      return ladders
  
  @staticmethod
  def buildChutes():
      chutes = [[0 for x in range(2)] for x in range(10)]
      chutes[0][0] = 9
      chutes[0][1] = 3
      chutes[1][0] = 12
      chutes[1][1] = 6
      return chutes
  
  class Check(Player):
      def __init__(self):
      super(Check,self).__init__()
  
  def checkLadders(self):
      ladders = Path.buildLadders()
      for i in range(0,len(ladders),1):
          if self.getPosition() == ladders[i][0]:
              self.position = self.setPosition(ladders[i][1])
              print(str(self.name) + " Landed on a Ladder! from " + \
                    str(ladders[i][0]) +" to " + str(ladders[i][1]))
  
  def newPosition(self):
      return self.position
  
  def checkChutes(self):
      chutes = Path.buildChutes()
      for i in range(0,len(chutes),1):
          if self.getPosition() == chutes[i][0]:
              self.position = self.setPosition(chutes[i][1])
              print(str(self.name) + " Landed on a Chutes!")
  
  class Match_Position(Player):
  def __init__(self,name):
      super(Match_Position,self).__init__(name)
      self.match = [[70,235],
                  [180,235],
                  [290,235],
                  [400, 235],
                  [400, 140],
                  [290, 140],
                  [180, 140],
                  [70, 140],
                  [70, 45],
                  [180, 45],
                  [290, 45],
                  [400, 45]]
      self.name = name
      self.players = Player(self.name)
      self.pos = self.players.getPosition()
      self.position_actual = []
      self.__str__()
      self.actualpos()
  
  def __str__(self):
      for j in range(len(self.match)):
          if self.pos == (j+1):
              self.position_actual.append(self.match[j][0])
              self.position_actual.append(self.match[j][1])
  
  def actualpos(self):
      return self.position_actual
  
  class Display(object):
  def __init__(self,master,img,name):
      canvas_width = 650
      canvas_height = 300
      self.name = name
      print(self.name)
      self.pos = Match_Position(self.name).actualpos()
      print(self.pos)
      self.canvas = Canvas(master, width = canvas_width, height = canvas_height, bg = "yellow")
      self.canvas.grid(padx=0, pady=0)
      self.canvas.create_image(300,150,anchor=CENTER, image = img)
      self.animate(master)
  
  def animate(self,master):
      Button(master, text= "ROLL", command=self.say_hello(self.name[0])).grid( row=3, column=0, sticky=E)
      Button(master, text= "ROLL", command=self.say_hello1(self.name[1])).grid( row=3, column=1, sticky=E)
  
  def say_hello(self,name):
      self.name = name
      self.name = Player(self.name)
      self.name.spin()
      Check.checkLadders(self.name)
      Check.checkChutes(self.name)   
      x = self.pos[0]
      y = self.pos[1]
      self.canvas.create_oval(x,y,x+20,y+20, fill='blue')
  
  def say_hello1(self,name):
      self.name = name
      self.name = Player(self.name)
      self.name.spin()
      Check.checkLadders(self.name)
      Check.checkChutes(self.name)   
      x = self.pos[0]
      y = self.pos[1]
      self.canvas.create_oval(x,y,x+20,y+20, fill='red')
  
  
  
  class BounceController(object):
  def __init__(self):
      master = Tk()
      master.title("Snake and Ladder")
      master.geometry("700x350")
      img = PhotoImage( file = "puzzlor-chutes-and-ladders.gif" )
      name = ['n','s']
      Display(master,img,name).animate(master)
      master.mainloop()
  
  def main():
  BounceController()
  
  main()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/whkuW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/whkuW.png" alt="enter image description here"></a></p>
  
  <p>It printed out this, but the error: 
  "'Player' object does not support indexing" pop out.
  What is object does not support indexing error is?</p>
  
  <p>And when I click the button, the oval does not actually move.
  And using tkinter Button, I can call the method, right?</p>
  
  <p>But by doing so, if I want to make for example, clicking the button, result to the oval moving to different location, how do I achieve that? Since as my code, above, the oval does not move eventhough the button is clicked.</p>
  
  <p>Thanks. Since I'm quite new to python and programming, any help would be such a gratitude.</p>