title: How to start moving a turtle via space bar with python
body: <p>I'm trying to set up a simple turtle program in python where I can start moving the turtle with a press of the space bar, and he keeps moving until I hit the space bar again. I can get him to move a fixed distance with the space press but can't get it to continue.</p>
  
  <p>Here is what I'm working with:</p>
  
  <pre><code>from turtle import *
  
  
  # PUT YOUR CODE HERE
  setup(800,600)
  home()
  pen_size = 2
  color("blue")
  title("Turtle")
  speed("fastest") 
  drawdist= 25 
  current_state = penup
  next_state = pendown
  
  #Button Instructions
  def move_up():
          seth(90)
          forward(drawdist)
  
  def move_down():
          seth(270)
          forward(drawdist)
  
  def move_left():
          seth(180)
          forward(drawdist)
  
  def move_right():
          seth(0)
          forward(drawdist)
  
  
  def space_bar():
      seth(90)
      forward(drawdist)
      global current_state, next_state
      next_state()
      current_state, next_state = next_state, current_state
  
  #Change Pen Color
  def red():
          color("red")
  
  def green():
          color("green")
  
  def blue():
          color("blue")
  
  
  #Button Triggers
  s= getscreen()
  
  s.onkey(move_up,"Up")
  
  s.onkey(move_down,"Down")
  
  s.onkey(move_left,"Left")
  
  s.onkey(move_right,"Right")
  
  s.onkey(space_bar,"space")
  
  s.onkey(red,"r")
  
  s.onkey(green,"g")
  
  s.onkey(blue,"b")
  
  listen()
  
  done()
  </code></pre>