Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a table with PySimpleGUI and Pandas

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()
like image 778
Emad Avatar asked Oct 19 '25 10:10

Emad


1 Answers

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()
like image 197
Jason Yang Avatar answered Oct 22 '25 04:10

Jason Yang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!