PySimpleGUI 表 - 无法创建列表列表

PySimpleGUI tables - unable to create list of lists

我无法使用 PySimpleGUI.Table 因为我无法创建列表列表,请查看我的代码:

def is_compiled(file):
    full_path = main_path + 'models_data/'+ file[:-3]
    return isdir(full_path)   #Returns bool True of False


models_src = [f for f in listdir(model_src_path) if isfile(join(model_src_path, f))] 
is_compiled_list = [str(is_compiled(f)) for f in models_src] 
table_list = [models_src,is_compiled_list]
print(table_list)

打印我的列表显示:

[['CNN_v1.py', 'test.py'], ['False', 'True']]

类型为

但是当我尝试将此列表放入 sg.Table 时:

table_headings = ['name','iscompiled?']
layout = [[sg.Table(table_list,headings=table_headings]]
window = sg.Window("Demo", layout, margins=(500, 300))
while True:
    event, values = window.read()

我收到此错误消息:

list indices must be integers or slices, not Text

我知道这可能是一个非常简单的解决方案,但我花了几个小时试图找到它,但我找不到。感谢您的帮助!

编辑:打字错误

此异常可能是由您未在此处显示的代码引起的。

例如,在下面的代码中,[sg.Table(table_list, headings=table_headings)] 在下一行带有 [sg.Text('Hellow World')]

import PySimpleGUI as sg

table_list = [['CNN_v1.py', 'test.py'], ['False', 'True']]
table_headings = ['name','iscompiled?']
layout = [
    [sg.Table(table_list, headings=table_headings)]
    [sg.Text('Hellow World')]
]
sg.Window('Title', layout).read(close=True)

就像下面的代码,sg.Text('Hellow World') 将被认为是 list1 的索引,这就是为什么你得到异常 TypeError: list indices must be integers or slices, not Text

list1 = [sg.Table(table_list, headings=table_headings)]
layout = [
    list1[sg.Text('Hellow World')]
]

列表中的任意两项之间应该用逗号分隔,如

import PySimpleGUI as sg

table_list = [['CNN_v1.py', 'test.py'], ['False', 'True']]
table_headings = ['name','iscompiled?']
layout = [
    [sg.Table(table_list, headings=table_headings)],    # A comma missed between any two items
    [sg.Text('Hellow World')]
]
sg.Window('Title', layout).read(close=True)