Python Forum

Full Version: how to add elements in the other window? (pysimplegui)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to add text elements every time I press the "Add" button

import PySimpleGUI as sg

layout1 = [
            [
              sg.InputText(size=(15, 1), justification="center", key="-OUTPUT-"),
              sg.Button("Push"),
              sg.Button("Add"),
            ],
          ]

window1 = sg.Window("todo", layout1, size=(300, 50))

window2 = False

def add_elements(key="-TEXT6-"):
    return [sg.Text(["6. Empty", key])]

while True:
    event, values = window1.Read(timeout=100)
    if event == "Exit" or event == sg.WIN_CLOSED:
        break
    if (not window2 and event == "Push"):
        window2 = True
        layout2 = [
            [ 
              sg.Text("1. Empty", key="-TEXT-") 
            ],
            [
              sg.Text("2. Empty", key="-TEXT2-") 
            ],
            [
              sg.Text("3. Empty", key="-TEXT3-") 
            ],
            [
              sg.Text("4. Empty", key="-TEXT4-") 
            ],
            [
              sg.Text("5. Empty", key="-TEXT5-") 
            ],
          ]
        windows = sg.Window("Output", layout2, size=(500, 500))
    if window2:
        event2, values2 = windows.Read(timeout=100)
        if event2 == sg.WIN_CLOSED:
            window2 = False
            windows.close()
        if event == "Push":
            output = windows["-TEXT-"].update(values["-OUTPUT-"])
            #print(output)
        if event == "Add":
            layout2.append([sg.Text(add_elements())])
            print(layout2)
    
window1.close()
but, every time I press "Add" it doesn't display the GUI ... but when I use the print function it displays the place of the object in memory