PySimpleGUI Canvas object goes down, right when dragging

I have implemented a way to select objects and drag them. But there is one problem, everytime I tried to drag, the object goes down and right fast instead of following my mouse. I tried every solution, it won’t work. If you want to help me, here’s the code:

import PySimpleGUI as sg

sg.theme('DefaultNoMoreNagging')

items_files = [  [sg.Button(pad = (0, 0), tooltip = 'Delete from Frontmost', key = 'DelF')]  ]

tab2 = [  [sg.Button(key = 'Rect', pad = (0, 0), tooltip = 'Rectangle')]  ]

BC = 'white'
CW = 600
CH = 450
LXM = (CW / 2)
LYM = (CH / 2)

mid_left = [  [sg.Text(text = "X:"), sg.Input(default_text = "0", key = "TLX", size = (3, 1))],
              [sg.Text(text = "Y:"), sg.Input(default_text = "0", key = "TLY", size = (3, 1))],
              [sg.Text(text = "Scale X:"), sg.Input(default_text = "0", key = "TSX", size = (3, 1))],
              [sg.Text(text = "Scale Y:"), sg.Input(default_text = "0", key = "TSY", size = (3, 1))]  ]

can = sg.Canvas(size = (CW, CH), background_color = BC, border_width = 1, key = "canvas")

mid_screen = [  [sg.Frame("Insert Values", mid_left, expand_x = True, expand_y = True), can]  ]

layout = [  [sg.Frame("", items_files, pad = (1, 1), expand_x = False, expand_y = False), sg.TabGroup([[sg.Tab('Insert', tab2)]])],
            [mid_screen]  ]
window = sg.Window('title', layout, finalize = True)
tkc = can.TKCanvas
while True:
    event, values = window.read()
    if event in (None, sg.WIN_CLOSED, 'Exit'):
        break
    N = 0

    OL = [0]

    TLX = values["TLX"]
    TLY = values["TLY"]
    TSX = values["TSX"]
    TSY = values["TSY"]
    LT = 1
    FC = 'red'
    LC = 'black'

    def sel(e):
        print (e)

    def move(e):
        tkc.move(e.widget.find_withtag('current'), e.x, e.y)

    def DeleteObj():
        pum = N
        tkc.delete(OL[pum])
        del OL[pum]
        pum = N - 1

    if event == 'Rect':
        OL.insert(N, tkc.create_rectangle((float(LXM) + float(TLX) + float(TSX)), (float(LYM) + float(TLY) + float(TSY)), (float(LXM) + float(TLX) - float(TSX)), (float(LYM) + float(TLY) - float(TSY)), fill = FC, outline = LC, width = LT,  tag = N))
        tkc.tag_bind((N + 1), '<1>', sel)
        tkc.tag_bind((N + 1), '<B1-Motion>', move)
        N = N + 1
        print (OL)
        print (N)

    if event == 'DelF':
        DeleteObj()
        print (OL)
        print (N)

window.close()

tkc.move(...) moves the widget relative to its current position, e.g. move it 10 pixels to the right. What you want is tkc.moveto(...).

Thanks. But, if the line width or line thickness is a decimal (e.g. “2.5”), it will “draw” instead of move (which might indicate I am inserting more squares than possible). What should I do to eliminate the trail behind as I drag around the canvas? Also, how to I delete objects, now the DeleteObj function is not working anymore.