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

WoLvES 2.0
  • 41
  • 5

1 Answers1

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

Jason Yang
  • 11,284
  • 2
  • 9
  • 23
  • Thank you very much, I couldn't figure out a way to how to add `+` . – WoLvES 2.0 Aug 19 '21 at 10:55
  • 1
    use `+` to join two list to as one row, maybe one of lists generated by list comprehension. – Jason Yang Aug 19 '21 at 12:15
  • 1
    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. https://pysimplegui.readthedocs.io/en/latest/#generated-layouts-for-sure-want-to-read-if-you-have-5-repeating-elementsrows – Mike from PSG Aug 23 '21 at 18:14