title: Drawing straight lines on a tkinter canvas with Grid on python with mouse
body: <p>so currently I am working on a program that will allow origami artists to create crease patterns on their computer using this program. So far I have a program that draws a grid on the canvas and allows the user to draw a freeform line  , however, I require the user to able to draw straight lines but I'm unsure on how to adapt this code so the user can draws straight lines not freeform squiggle. Here is my code so far:</p>
  
  <pre><code>from tkinter import *
  
  Mouse = "up"
  xold, yold = None, None
  def DrawGrid(drawing_area, line_distance):
  
     for x in range(line_distance,600,line_distance):
         drawing_area.create_line(x, 0, x, 600, fill="#d3d3d3")
  
     for y in range(line_distance,600,line_distance):
         drawing_area.create_line(0, y, 600, y, fill="#d3d3d3")
  
  def main():
      root = Tk()
      drawing_area = Canvas(root, width=600, height=600, bg='white')
      drawing_area.pack()
      DrawGrid(drawing_area, 10)
      drawing_area.bind("&lt;Motion&gt;", motion)
      drawing_area.bind("&lt;ButtonPress-1&gt;", Mousedown)
      drawing_area.bind("&lt;ButtonRelease-1&gt;", Mouseup)
  
      root.mainloop()
  
  def Mousedown(event):
      global Mouse
      Mouse = "down"         
  
  def Mouseup(event):
      global Mouse, xold, yold
      Mouse = "up"
      xold = None           
      yold = None
  
  def motion(event):
      if Mouse == "down":
          global xold, yold
  
      if xold is not None and yold is not None:
          event.widget.create_line(xold,yold,event.x,event.y,smooth=TRUE)
  
      xold = event.x
      yold = event.y
  
  
  main()
  </code></pre>
  
  <p>Thank you, 
            Mistry27</p>