2

I tried a to loop some elements in PySimpleGUI using PySimpleGUIQt here's the code:

list_1 = ['a', 'b', 'c', 'd']
list_2 = ['e', 'f', 'g', 'h']

layout = [[Sg.Column([[Sg.Input(do_not_clear=True, size=(20, 0.7), enable_events=True, key=f'G_INPUT0{j}'), Sg.Column([[Sg.Input(do_not_clear=True, size=(14, 0.7), enable_events=True, key=f'INPUT{i}{j}') for i in range(9)]])],[Sg.Listbox(list_1, size=(20, 0.7), enable_events=True, key=f'G_LIST0{j}'), Sg.Column([[Sg.Listbox(list_1, size=(14, 0.7), enable_events=True, key=f'LIST{i}{j}')for i in range(9)]])],[Sg.Text(' G: ', size=(20, 0.7), key=f'G_TEXT{j}'), Sg.Column([[Sg.Text(f' T{i}: ', size=(14, 0.7), key=f'TEXT{i}{j}')for i in range(9)]])]])]for j in range(3)]
window = Sg.Window('Sample GUI', layout, finalize=True)
while True:
    event, values = window.Read()
    print(event)
    print(values)

Output: enter image description here The issue is if I want to add new loop I need to add Sg.Column which makes extra space, and add one more loop but I don't wanna use Sg.Column so can anyone tell me a fix where I can get get similar to this result enter image description here made using ms paint

1 Answer 1

2

Example code without any sg.Column

import PySimpleGUIQt as Sg

list_1 = ['a', 'b', 'c', 'd']
list_2 = ['e', 'f', 'g', 'h']

layout = []

for j in range(3):
    layout += [
        [Sg.Checkbox("Some text", pad=(3, 20))],
        [Sg.Input(do_not_clear=True, size=(20, 0.7), enable_events=True, key=f'G_INPUT0{j}')] +
        [Sg.Input(do_not_clear=True, size=(14, 0.7), enable_events=True, key=f'INPUT{i}{j}') for i in range(9)],
        [Sg.Listbox(list_1, size=(20, 0.7), enable_events=True, key=f'G_LIST0{j}')] +
        [Sg.Listbox(list_1, size=(14, 0.7), enable_events=True, key=f'LIST{i}{j}') for i in range(9)],
        [Sg.Text(' G: ', size=(20, 0.7), key=f'G_TEXT{j}')] +
        [Sg.Text(f' T{i}: ', size=(14, 0.7), key=f'TEXT{i}{j}') for i in range(9)]
    ]

window = Sg.Window('Sample GUI', layout, finalize=True)

while True:
    event, values = window.read()
    if event == Sg.WINDOW_CLOSED:
        break
    print(event, values)

window.close()

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much, I couldn't figure out a way to how to add + .
use + to join two list to as one row, maybe one of lists generated by list comprehension.
The Demo Program Demo_Layout_Generation.py shows the ways that you can use the + operator with layouts to make all kinds of these combined layouts that use list comprehensions and loops. Really handy operations like in Jason's example. The documentation has a section about them too that you might like. pysimplegui.readthedocs.io/en/latest/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.