I'm stuck on a critical part of a program I am writing. How can I repeat a layout x times and for the keys present in each layout to be different? I thought about doing a layout that has 100 already done and repeat heaps of make visible/not visible (depending on the data number available), but is there a more efficient way?
def get_selections_layouts():
GSIZE = (80, 50)
graph = sg.Graph(GSIZE, (0, 0), GSIZE, key='-GRAPH-', background_color='blue')
graph1 = sg.Graph(GSIZE, (0, 0), GSIZE, key='-GRAPH1-', background_color='pink')
spacer = sg.Column([[sg.Text('')]])
layoutSelections = sg.Column([[sg.T("Data", key='dataset', justification='left'), sg.Push(),
graph, graph1],
[sg.HorizontalSeparator(pad=(0, 10))], ],
expand_x=True)
try:
data1 = graph.draw_text(data[1], (GSIZE[0] // 2, GSIZE[1] // 1.5), font=('Any 20', 14),
text_location=sg.TEXT_LOCATION_CENTER, color='white')
except:
pass
try:
data2 = graph1.draw_text(data[2], (GSIZE[0] // 2, GSIZE[1] // 3), font=('Any 40', 8),
text_location=sg.TEXT_LOCATION_CENTER, color='white')
except:
pass
return layoutSelections
layoutSelections = get_selections_layouts()# and repeat this X times, with each layout having diff keys
layoutDataset = [[dataHeading],[start_time_text,data_total],
layoutCol,[sg.HorizontalSeparator()],[layoutSelections]
]
and in the while loop
elif event == sg.TIMEOUT_KEY:
currentSituation = bfo.getData
try:
data1 = currentSituation[0]#need data1 + key for layout number 1
window['-GRAPH-'].update(visible=True)#need -GRAPH- + key for layout number 1
except:
window['-GRAPH-'].update(visible=False)
try:
data2 = currentSituation[0]#need data2 + key for layout number 1
window['-GRAPH1-'].update(visible=True)#need -GRAPH1- + key for layout number 1
except:
window['-GRAPH1-'].update(visible=False)
and repeat that try/except block of code for all layoutSelections with their respective keys.

tuplesas your keys. Instead of"-KEY1-"use("-KEY-", 1). Then it's easy to "reuse" keys at least in how your code looks. The first term of the tuple stays the same and the second one is the "layout number". There are demo programs and areas of the documentation that describe this technique. Maybe search for "tuple" in them.