Python Forum
how to add elements in the other window? (pysimplegui)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to add elements in the other window? (pysimplegui)
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 347 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  PysimpleGUI window update dynamically SamLiu 6 3,888 Apr-05-2023, 02:32 PM
Last Post: SamLiu
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 13,417 Jan-18-2021, 10:21 PM
Last Post: Serafim
  tkinter window and turtle window error 1885 3 6,625 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 8,978 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020