0

I have a database with two columns: ID, Color (1, "red", 2 , "green", etc.) and I am trying to dynamically display the list of the colors with a Checkbox next to the description. Is this possible?

This is what I am trying to do dynamically rather than static.

import PySimpleGUI as sg
layout =[[sg.Checkbox('DB RED', key='-DB ID 1-')],
        [sg.Checkbox('DB GREEN', key='-DB ID 2-')],
        [sg.Checkbox('DB BLUE', key='-DB ID 3-')]]
 window = sg.Window('Test Window', layout)
 event, values = window.read()
 window.close()

Thanks for any assistance.

1 Answers1

0

Quick and dirty:

import PySimpleGUI as sg

db_values = [
    'DB RED', 'DB GREEN', 'DB BLUE'
]

layout = []
cnt = 1    

for entry in db_values:
    layout.append([sg.Checkbox(entry, key=f'-DB ID {cnt}-')])
    cnt += 1

window = sg.Window('Test Window', layout)
event, values = window.read()
window.close()
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 19 '21 at 06:14