使用 PySimpleGUI 和 Pandas 制作 table

Making a table with PySimpleGUI and Pandas

我是 PySimpleGUI 和 pandas 的新手。我想在 GUI 中创建一个 table。如何添加每个 header 的条目?我的代码有问题。

import pandas
import PySimpleGUI
headers = {'Integers':[], 'Strings':[], 'Normallized Floats':[], 'Binaries':[]}
table = pandas.DataFrame(headers)
window = PySimpleGUI.Window(title = 'Sample excel file', layout = [[PySimpleGUI.Table(values = table, headings = list(headers))]] , margins = (200,200))
event, value = window.read()

table 的数据是列列表的行列表。

此处没有数据记录,为避免出错,必须为sg.Table设置选项auto_size_columns=False和每列宽度。

import pandas
import PySimpleGUI as sg

headers = {'Integers':[], 'Strings':[], 'Normalized Floats':[],
    'Binaries':[]}
table = pandas.DataFrame(headers)

headings = list(headers)
values = table.values.tolist()

sg.theme("DarkBlue3")
sg.set_options(font=("Courier New", 16))

layout = [[sg.Table(values = values, headings = headings,
    # Set column widths for empty record of table
    auto_size_columns=False,
    col_widths=list(map(lambda x:len(x)+1, headings)))]]

window = sg.Window('Sample excel file',  layout)
event, value = window.read()