title: Why is the “root.after ()” method not stoppable?
body: <p>I'm trying to make a simple tool-path program with directional buttons. It works, but sometimes releasing the button is ineffective and the turtle stops just clicking the "Home" button. Else it just runs continuously as if I did not release the button.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>from tkinter import *
  from turtle import RawTurtle, TurtleScreen
  
  def showPos():
      monitor.delete('1.0', END)
      monitor.insert(END, "X: " + str(tool.ycor()) +" Z: " + str(tool.xcor()))
  
  def goHome():
      tool.home()
      showPos()
      stop_move()
  
  def goUp():
      tool.sety(tool.ycor() + 10)
  
  def goDown():
      tool.sety(tool.ycor() - 10)
  
  def goRight():
      tool.setx(tool.xcor() + 10)
  
  def goLeft():
      tool.setx(tool.xcor() - 10)
  
  def stop_move():
      global jobid
      root.after_cancel(jobid)
  
  def move(direction):
      global jobid
  
      if direction == "-X":
          goDown()
  
      if direction == "+X":
          goUp()    
  
      if direction == "-Z":
          goLeft()
  
      if direction == "+Z":
          goRight()    
  
      jobid = root.after(10, move, direction)
      showPos()
  
  jobid = None
  
  root = Tk()
  root.title("CNC Lathe")
  
  canvas = Canvas(root, width=800, height=600)
  canvas.pack()
  
  screen = TurtleScreen(canvas)
  screen.bgcolor("black")
  screen.register_shape("wnmg.gif")
  
  tool = RawTurtle(screen, shape="wnmg.gif")
  tool.pencolor("white")
  
  monitor = Text(root, height=1, width=16, font="Helvetica")
  monitor.pack()
  
  topFrame = Frame(root)
  topFrame.pack()
  middleFrame = Frame(root)
  middleFrame.pack()
  bottomFrame = Frame(root)
  bottomFrame.pack()
  
  for direction in ("-X", "+X", "-Z", "+Z"):
      if direction == "+X":
          button = Button(topFrame, text=direction)
          button.pack()
  
      if direction == "-X":
          button = Button(bottomFrame, text=direction)
          button.pack()
  
      if direction == "-Z":
          button = Button(middleFrame, text=direction)
          button.pack(side=LEFT)
  
      if direction == "+Z":
          button = Button(middleFrame, text=direction)
          button.pack(side=RIGHT)   
  
      button.bind('&lt;ButtonPress-1&gt;', lambda event, direction=direction: move(direction))
      button.bind('&lt;ButtonRelease-1&gt;', lambda event: stop_move())
  
  Button(middleFrame, text="Home", command=goHome).pack()
  
  root.mainloop()
  </code></pre>
  
  <p>I tried to set the variable "jobid" to "None" after the "root.after_cancel ()" method, but nothing changed. At times this does not seem to detect the release of the button. Does anyone know a solution?</p>