title: tKinter switch color on hotkey click
body: <p>I have a program that opens a window and a circle at the center that is filled green at the start. I want this circle to change from red to green  and green to red each time I press a button (r in this code) however I can only change the color once</p>
  <pre><code>from tkinter import *
  import keyboard
  
  if __name__ == '__main__':
      window = Tk()
  
      window.title(&quot;On Record&quot;)
      window.configure(width=500, height=300)
      window.configure(bg='lightgray')
      myCanvas = Canvas(window)
      myCanvas.pack()
  
  
      def daire(x, y, r, canvasName, color):  # center coordinates, radius
          x0 = x - r
          y0 = y - r
          x1 = x + r
          y1 = y + r
          return canvasName.create_oval(x0, y0, x1, y1, fill=color)
  
  
      # move window center
      winWidth = window.winfo_reqwidth()
      winwHeight = window.winfo_reqheight()
      posRight = int(window.winfo_screenwidth() / 2 - winWidth / 2)
      posDown = int(window.winfo_screenheight() / 2 - winwHeight / 2)
      window.geometry(&quot;+{}+{}&quot;.format(posRight, posDown))
      color = &quot;green&quot;
  
      def onKeyPress(event):
          print(&quot;pressed&quot;)
          counter = 0
          counter = counter + 1
          print(counter)
          if counter % 2 == 0:
              color = &quot;green&quot;
          else:
              color = &quot;red&quot;
          daire(190, 135, 120, myCanvas, color)
  
  
      window.bind(&quot;r&quot;, onKeyPress)
      daire(190, 135, 120, myCanvas, &quot;green&quot;)
      window.mainloop()
  </code></pre>