title: How To Make An Image Change When Pressing A Specific Key In TKinter In Python
body: <p>I am new to Python and was wondering how I could make an image change to another when a key is pressed.  I want my image to change from GuyUp.gif to GuyDown.gif when I press the down arrow key so it looks like my guy is actually walking normally.  My code in Python looks like this:</p>
  
  <pre><code>from tkinter import *
  tk = Tk()
  tk.title("Triangle Movement")
  tk.resizable(0, 0)
  canvas = Canvas(tk, width=500, height=500)
  canvas.pack()
  tk.update()
  guyup = PhotoImage(file = 'GuyUp.gif')
  canvas.create_image(5, 5, image = guyup, anchor = NW)
  def movetriangle(event):
      if event.keysym == 'Up':
          canvas.move(1, 0, -4)
      elif event.keysym == 'Down':
          canvas.move(1, 0, 4)
      elif event.keysym == 'Left':
          canvas.move(1, -4, 0)
      elif event.keysym == 'Right':
          canvas.move(1, 4, 0)
      elif event.keysym == 'w':
          canvas.move(2, 0, -4)
      elif event.keysym == 's':
          canvas.move(2, 0, 4)
      elif event.keysym == 'a':
          canvas.move(2, -4, 0)
      else:
          canvas.move(2, 4, 0)
  canvas.bind_all('&lt;KeyPress-Up&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-Down&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-Left&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-Right&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-w&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-s&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-a&gt;', movetriangle)
  canvas.bind_all('&lt;KeyPress-d&gt;', movetriangle)
  </code></pre>
  
  <p>I do have the two images and would like to put it in my elif statement with the keysym of 'Down'
  Thank you for your help!</p>