title: A button that linked 2 buttons together with a line (Tkinter)
body: <p>I had made another new change. Now it can sometimes draw lines between the buttons when I double clicked but it seems that it does not works the way that I intended too. Like I can connect any button when I clicked the 'Add line' button but instead it's kind of buggy. Sometimes it registered my double click and sometimes when I clicked button 1 and 5 and it connects 2 and 3 instead. So how can I do like, it will connect Button 2 and 3 when I only double clicked Button 2 and 3.</p>
  <pre><code>from tkinter import *
  import tkinter
  
  counter = 1
  undone = []
  
  numcount = 1
  
  def drag_start(event):
      widget = event.widget
      widget.startX = event.x
      widget.startY = event.y
  
  def drag_motion(event):
      global x, y
      widget = event.widget
      x = widget.winfo_x() - widget.startX + event.x
      y = widget.winfo_y() - widget.startY + event.y
      widget.place(x = x, y = y)
  
  def add_button():
      global btn
      btn = Button(canvas, text = 'Button ' + str(numcount))  
      btn.pack(side = tkinter.TOP, anchor = tkinter.NW)
      btn.bind('&lt;Button-1&gt;', drag_start)
      btn.bind('&lt;B1-Motion&gt;', drag_motion)
  
  def draw_line(event):
      global click_number
      global x1, y1
      if click_number == 0:
          x1 = x
          y1 = y
          click_number = 1
      else:
          x2 = x
          y2 = y
          canvas.create_line(x1, y1, x2, y2, width = 2, tag = 'line')
          click_number = 0
  
  def add_line():
      btn.bind('&lt;Double-Button-1&gt;', draw_line)
  
  def num():
      global numcount
      numcount += 1
      add_btn.config(text = 'Add Button')
  
  def func(*funcs):
      def combined_func(*args, **kwargs):
          for f in funcs:
              f(*args, **kwargs)
      return combined_func
  
  main = Tk()
  
  main.title('Drag and Drop')
  main.geometry('500x500')
  canvas = Canvas(main, width = 500, height = 500, background = 'white')
  canvas.pack(expand = YES, fill = BOTH)
  click_number = 0
  
  add_btn = Button(main, text = 'Add Button', command = func(add_button, num))
  add_btn.place(x = 400, y = 10)
  
  line_btn = Button(main, text = 'Add line', command = add_line)
  line_btn.place(x = 400, y = 40)
  
  main.mainloop()
  </code></pre>