I'm retrieving a large list of people from a database, then looping through each person to get their note/s and phone number/s. then displaying one person at a time with PySimpleGUI.
My issue is that it I'm doing multiple sql queries rather than just one (I don't know if this is an issue), and I have to repeatedly Finalize() and close() the screen, which creates a new window each time, rather than just refreshing the current page.
Am I able to refactor this so I don't have to close and create a new window each time?
Thank you.
# get all people
people = conn.execute('''SELECT * FROM people''')
people_tuple = people.fetchall()
# loop through all people
for index, person in enumerate(people_tuple):
# get persons notes
notes = conn.execute('''SELECT * FROM notes WHERE person_id = ?''', (person[0],))
notes_list = events.fetchall()
# get persons phone number/s
phone_numbers = conn.execute('''SELECT * FROM phone_numbers WHERE person_id = ?''', (person[0],))
# redacted #
window = main_window_layout(person, phone_num_list, notes_list).Finalize()
while True:
event, values = window.read()
# many if statements checking user input #
window.close()
def main_window_layout(person, phone_num_list, notes_list):
top_left_frame_1 = [[sg.Text("ID: " + str(person[0]), key='id', pad=(2,4))],
[sg.Text("Name: " + person[1] + " " + person[2], key='name', pad=(2,4))]]
frame_2 = [
[sg.Text(note[4], key='note_date', pad=(3, (12, 3))), sg.Text(note[6], key='note_info', pad=(3, (12, 3)))]
for note in reversed(notes_list)
]