Search code examples
pythonwindows-10pysimplegui

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


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:\Python\Lavoro.py", line 89, in <module>
    event = window.read()
            ^^^^^^^^^^^^^
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 10075, in read
    results = self._read(timeout=timeout, timeout_key=timeout_key)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 10146, in _read
    self._Show()
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 9886, in _Show
    StartupTK(self)
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 16866, in StartupTK
    _convert_window_to_tk(window)
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 16753, in _convert_window_to_tk
    PackFormIntoFrame(window, master, window)
  File "D:\Python\venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.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


Solution

  • 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('???')],