I have a code here in pysimplegui, and I want to update the SO
variable. The problem is that it doesn’t want to update, despite the printers doing so correctly and the presence of a return
thingy. I don’t know that’s wrong, since the code looks good. Here’s the code:
import PySimpleGUI as sg
import re
sg.theme('DefaultNoMoreNagging')
items_files = [ [sg.Text(text = "", key = "SelT"), sg.Button(pad = (0, 0), tooltip = 'Delete', key = 'DelS'), sg.Button(pad = (0, 0), tooltip = 'Print', key = 'Prin')] ]
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
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 = 2.5
FC = 'red'
LC = 'black'
def sel(e):
LY = SO
print (e)
P = re.findall(r'\d+', str(e.widget.find_withtag("current")))
print (P)
LY = str(P[0])
print (LY)
window["SelT"].update(LY)
return LY
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 == 'Prin':
print (SO)
if event == 'DelS':
tkc.delete(OL[int(SO)])
OL.pop(int(SO))
window.close()
(I added the “print” button to help in debugging).