Ports = tkinter,
PySimpleGUI Version: 4.29.0.5 Unreleased (directly from github)
tkinter version: 8.6.10
10 Python programming experience
10 Programming experience overall
Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)? YES
when swapping TextFields and InputTextFields in my Form (by button press), it seems that the InputTextField does not properly swap values after the first click and is "lagging behind". can be demonstrated below by clicking "Calculate" and "Swap" buttons.
My question is if i missing some update command to update the InputText fields correctly after changing their value by code.
import PySimpleGUI as sg
layout = [[sg.Text("clicking swap schould change line A with line B. However, input fields do not match result field...")],
[sg.Text("Input A:"), sg.InputText("AAA", key="stringA", size=(15,1), enable_events=True ),
sg.Checkbox("a1", default=False, key="a1", enable_events=True),
sg.Checkbox("a2", default=True, key="a2", enable_events=True),
sg.Checkbox("a3", default=False, key="a3", enable_events=True),
sg.Text("result A:"), sg.Text("not yet calculated", size=(35,1), key="resultA", relief="raised")
],
[sg.Text("Input B:"), sg.InputText("BBB", key="stringB", size=(15, 1), enable_events=True),
sg.Checkbox("b1", default=False, key="b1", enable_events=True),
sg.Checkbox("b2", default=False, key="b2", enable_events=True),
sg.Checkbox("b3", default=True, key="b3", enable_events=True),
sg.Text("result B:"), sg.Text("not yet calculated", size=(35, 1), key="resultB", relief="raised")
],
[sg.Button("Calculate"), sg.Button("Swap"), sg.Cancel()],
]
window = sg.Window('swapping and calculating', layout)
while True:
event, values = window.read()
print(event)
if event in (sg.WIN_CLOSED, 'Cancel'):
break
if event in ( "Calculate", "stringA", "stringB", "a1", "a2", "a3", "b1", "b2", "b3"):
window["resultA"].update(values["stringA"] + str(values["a1"]) + str(values["a2"]) + str(values["a3"]))
window["resultB"].update(values["stringB"] + str(values["b1"]) + str(values["b2"]) + str(values["b3"]))
if event == "Swap":
# --- update result ---
#window["resultA"].update(values["stringA"] + str(values["a1"]) + str(values["a2"]) + str(values["a3"]))
#window["resultB"].update(values["stringB"] + str(values["b1"]) + str(values["b2"]) + str(values["b3"]))
# --- swap ---
a = [values["stringA"], values["a1"], values["a2"], values["a3"]]
b = [values["stringB"], values["b1"], values["b2"], values["b3"]]
window["stringA"].update(b[0])
window["stringB"].update(a[0])
window["a1"].update(b[1])
window["b1"].update(a[1])
window["a2"].update(b[2])
window["b2"].update(a[2])
window["a3"].update(b[3])
window["b3"].update(a[3])
# ----- somehow the update commands above are not processed ---
#---- updating the result ------
window["resultA"].update(values["stringA"] + str(values["a1"]) + str(values["a2"]) + str(values["a3"]))
window["resultB"].update(values["stringB"] + str(values["b1"]) + str(values["b2"]) + str(values["b3"]))
print("a:",values["stringA"])
print("b:", values["stringB"])
window.close()
For "Swap", following code not correct
window["resultA"].update(values["stringA"] + str(values["a1"]) + str(values["a2"]) + str(values["a3"]))
window["resultB"].update(values["stringB"] + str(values["b1"]) + str(values["b2"]) + str(values["b3"]))
Should be
window["resultA"].update(values["stringB"] + str(values["b1"]) + str(values["b2"]) + str(values["b3"]))
window["resultB"].update(values["stringA"] + str(values["a1"]) + str(values["a2"]) + str(values["a3"]))
ahhhhhhhhhh, epic facepalm
thanks! !!!!!
Most helpful comment
For "Swap", following code not correct
Should be