Python错误:ValueError:maxarg在PySimpleGUI中为空序列

问题描述

运行上面的代码时,我在控制台中收到此错误

Traceback (most recent call last):
  File "c:/Users/rdhin/OneDrive/Desktop/Rissistant/cam3.py",line 155,in <module>
    event,values = window.read()
  File "C:\python38\lib\site-packages\PySimpleGUI\PySimpleGUI.py",line 7568,in Read
    results = self._read(timeout=timeout,timeout_key=timeout_key)
  File "C:\python38\lib\site-packages\PySimpleGUI\PySimpleGUI.py",line 7623,in _read
    self._Show()
  File "C:\python38\lib\site-packages\PySimpleGUI\PySimpleGUI.py",line 7371,in _Show
    self.NumCols = max(len(row) for row in self.Rows)
ValueError: max() arg is an empty sequence

我不知道是什么原因引起的,但是这是我编写的代码

# Start the process
if __name__ == "__main__":

    # MARK: Setting up the GUI ~ lines 148-
    sg.theme('DarkBlue')
    layout = [[sg.Text("Hi,I am C.A.M.")],[sg.Text('Enter something in the text field,type the mic button,or say \'hey Cam!\'')],[sg.InputText(default_text="Enter a command here")],[sg.Button("Mic")],[sg.Button("Process")]]

    # Create the window
    window = sg.Window('C.A.M.')
    while True:

        event,values = window.read()
        if event in (None,'Cancel','Bye'):
            break
        print(values[0])

解决方法

在查看文档时,您似乎需要将参数layout添加到sg.Window('C.A.M.')

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...