I want to change a row of layout within a frame by changing event from combobox. And change back when first value from combobox is triggered.
When the window starts, it looks like below.

When user change value in combobox from Class A to Class B.
Window updates with new frame showing Class B.
window[key-name].update(visible=True) does't work with frame?
The Code:
import PySimpleGUI as sg
sg.theme("Reddit")
layout = [ [sg.Frame(
layout=[
[sg.Text("ID:",key='-ID-',size=(10, 1)),
sg.InputText(key='-section-id-',size=(10, 1), tooltip=" Define an id")
],
[
sg.Frame(
layout=[
[sg.Text("Student:",key='-student-',size=(10, 1)),
sg.InputText(default_text="25",key='-Class1-',size=(5, 1)),
sg.InputText(default_text="25",key='-Class2-',size=(5, 1)),
sg.Combo(['Yes', 'No'],key='-Yes&No-', default_value='Yes'),
sg.Combo(['A','B'],key='-A-B-',default_value='A')],
],
title="Student I",
relief=sg.RELIEF_GROOVE,
)
],
[
sg.Frame(
layout=[
[sg.Text("Student in A:",key='-IN-A-',size=(10, 1)),
sg.InputText(default_text="20",key='-MALE-',size=(5, 1), tooltip=" Number of males in Class A"),
sg.InputText(default_text="30",key='-FEMALE-',size=(5, 1), tooltip=" Number of females in Class A"),
sg.Combo(['A1','A2'],key='-A1-A2-',default_value='A1'),
sg.Combo(['Class A','Class B'],key='-CLASS-A-CLASS-B-',default_value='Class A',size=(8,1),
enable_events=True)],
],
title="Main class",
relief=sg.RELIEF_GROOVE,
)
],
# [
# sg.Frame(
# layout=[
# [sg.Text("Student in B:", key='-IN-A-', size=(10, 1)),
# sg.InputText(default_text="10", key='-FEMALE-', size=(5, 1), tooltip=" Number of females in Class B"),
# sg.InputText(default_text="30", key='-FEMALE-', size=(5, 1), tooltip=" Number of males in Class B"),
# sg.Combo(['B1', 'B2'], key='-B1-B2-', default_value='B1'),
# sg.Combo(['Class A', 'Class B'], key='-CLASS-A-CLASS-B-', default_value='Class B', size=(8, 1),
# enable_events=True)],
# ],
# title="Main class",
# relief=sg.RELIEF_GROOVE,
# )
# ]
],
title="Add an ID",
relief=sg.RELIEF_GROOVE,
)
],
[sg.Push(),sg.Button('Add ID',key='-Add-ID-',size=(10,1),font=("",8,"bold")),
sg.Button('Cancel',key='-Cancel-',size=(5,1),font=("",8,"bold"))]
]
window = sg.Window("Add an ID", layout, resizable=True, keep_on_top=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == '-Cancel-':
sys.exit()
if event == '-CLASS-A-CLASS-B-' and values['-CLASS-A-CLASS-B-'] == 'Class B':
window.refresh()
print('Tested ok!'+' '+values['-CLASS-A-CLASS-B-'])
window.close()


