I am making some lines that deletes an object with a given tag (i.e. the one with the "current"
tag, the one that is clicked), but it doesn’t work with the tkc.delete("current")
thingy. I need a method to delete not just the object, but the item in the list where object is going to get deleted, wether it is by finding location within list with tag or not. Should I ditch the OL
list? Any suggestions welcome (but make it clear if needed). Here’s the code:
import PySimpleGUI as sg
sg.theme('DefaultNoMoreNagging')
items_files = [ [sg.Text(text = "", key = "SelT"), sg.Button(pad = (0, 0), tooltip = 'Delete from Frontmost', key = 'DelO')] ]
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] ]
N = 0
CS = 1
OL = [0]
SO = None
window = sg.Window('title', layout, finalize = True)
tkc = can.TKCanvas
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
TLX = values["TLX"]
TLY = values["TLY"]
TSX = values["TSX"]
TSY = values["TSY"]
LT = 3
FC = 'red'
LC = 'black'
def sel(e):
print (e)
SO = e.widget.find_withtag("current")
window["SelT"].update(SO)
def move(e):
tkc.moveto(e.widget.find_withtag('current'), e.x, e.y)
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 = 'R' + str(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 == 'DelO':
tkc.delete("current") #How do you find location in list with tag?
OL.pop(int("current"))
window["SelT"].update(None)
print (OL)
print (N)
window.close()