Reputation: 155
I'm new to PySimpleGUI and pandas. I want to make a table in the GUI. How can I add the entries of each header? My code has problems.
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()
Upvotes: 4
Views: 7863
Reputation: 13061
Data for table is row list of column list.
Here, no data record, to avoid error, have to set option auto_size_columns=False
and width for each column for sg.Table
.
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()
Upvotes: 4