How to fix TypeError: cannot unpack non-iterable Button object

Question:

I was writing my PySimpleGUI program and it (Still) does not load
This is the error it gives me:

Traceback (most recent call last):
  File "D:PythonLavoro.py", line 89, in <module>
    event = window.read()
            ^^^^^^^^^^^^^
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 10075, in read
    results = self._read(timeout=timeout, timeout_key=timeout_key)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 10146, in _read
    self._Show()
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 9886, in _Show
    StartupTK(self)
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 16866, in StartupTK
    _convert_window_to_tk(window)
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 16753, in _convert_window_to_tk
    PackFormIntoFrame(window, master, window)
  File "D:PythonvenvLibsite-packagesPySimpleGUIPySimpleGUI.py", line 14943, in PackFormIntoFrame
    width, height = element_size
    ^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable Button object

This is the Code
I Put ??? For privacy

layout = [ [sg.Text('???')],
           [sg.Text('???')],
           [sg.Text('???', sg.Button('???'))],
           [sg.Text('???')],
           [sg.Text('???')] ]

window = sg.Window('???', layout)

while True:
    event, values = window.read()

I tried using this

event = window.read
values = window.read

It didnt work so now im stuck here

Asked By: Gigetto Lai

||

Answers:

You did not specify the error message clearly, but as per your code you tried using:

event = window.read
values = window.read

Try using the following:

while True:   
    event = window.read()
    values = window.read()

    if event == sg.WIN_CLOSED:
        break
    if event == 'Any_other_event':
        #do that action
  
window.close()

if this doesn’t work for you, please update your question will full error message so we can look through it.

Answered By: Hari Acharya

I am not sure what kind of layout you are going for but I believe this line:

[sg.Text('???', sg.Button('???'))],

should be

[sg.Text('???'), sg.Button('???')],
Answered By: Marko Borković